|
Category
Library Section
Description
Special variables that can be used within a Library formula to access the arguments that were passed to it
Notes
Library items can be referenced either with or without arguments.
When referenced with arguments (so that the reference looks like a function call), the item formula can obtain the values passed in as arguments by using these numbered variables. Arg1 is the first (leftmost) argument, Arg2 the second one, and so on.
Library function arguments can be either numbers or strings (or formulas that evaluate to either).
Arg1 through Arg9 are passed by value: each is evaluated once, at the bar where the library function is referenced, and passed in as a single value. For example myLibFunc(Close) evaluates Close to the current close and passes that one number. A by-value argument is a constant, not an array, so it should not be given a bar offset such as Arg1[1] or passed to a multi-bar function.
Ref1 through Ref9 are those same arguments passed by reference: Ref1 is the first argument, Ref2 the second, and so on, but each is re-evaluated in the calling formula's context every time it is used. A by-reference argument therefore behaves as an array -- Ref1[1] returns the prior bar's value, and an argument can be used in a multi-bar function such as MA(Ref1, 20).
A library formula may freely mix the two forms, even for the same argument -- use ArgN where you want the fixed value at the call bar and RefN where you want the full series.
For example, a library function defined as myMA: MA(Ref1, Arg2) and invoked as myMA(Close, 20) computes a true 20-bar average of the close: Ref1 supplies the close as a series while Arg2 supplies the constant length 20. Using Arg1 in place of Ref1 would instead average 20 copies of the current close (i.e. just return the close). By-reference gives the same result as by-value whenever an argument does not vary by bar, and differs only when it does.
If an argument expression evaluates to n/a at the call bar, the call does not fail as a whole: any ArgN read of that argument sees n/a, while RefN uses are unaffected, since a by-reference argument is only evaluated where it is actually used. (Through RealTest 2.0.32.1, one n/a argument caused the entire call to return n/a even if the argument was never read by value.)
|