Category
General-Purpose Functions
Description
Evaluate for a different stock/contract or strategy or bar size
Syntax
Extern(item_reference, expression)
Parameters
item_reference - a stock symbol, a strategy name, or a bar size
expression - formula
Notes
The default context in all formulas is the current stock for bar data items and the current strategy for daily stats items and position information.
Extern allows you temporarily change context to a different stock or strategy or bar size.
To reference a stock, use a $ to prefix the symbol of the desired stock, e.g. Extern($MSFT, C)
If a stock symbol already starts with a $, e.g. $SPX, you will have to add another $, hence Extern($$SPX, C).
The special symbol $CalSym can be used to reference the CalendarSym of the current strategy.
See also Symbol References.
There are also special types of Extern references available for individual futures contracts and corresponding industry index symbols.
To reference a Strategy, Benchmark or StatsGroup, use a @ to prefix the name of the desired strategy, e.g. Extern(@mr_short, S.Equity)
To calculate a formula using a specific bar size, use a ~ to prefix the name of the bar size, e.g. Extern(~Weekly, MA(C, 20))
Note that the expression referenced can be any formula, and it is most efficient to do as much as possible in a single Extern function. For example, Extern($SPY, C > MA(C,20)) would be preferable to Extern($SPY,C) > Extern($SPY, MA(C,20)) or, even worse, Extern($SPY,C) > MA(Extern($SPY,C), 20) -- though all would return the same result.
It is also possible to refer to a dynamic (non-constant) external strategy or symbol, either by string or number, using StratRef or SymRef.
The Extern function can be nested, e.g. Extern(@mystrat, Extern($XYZ, BarsHeld)) to determine how long mystrat has held a position in XYZ.
|