reference

Syntax

reference <StudyName>(parameter1=value1,.., parameterN=valueN ).<PlotName>

Description

References a plot from another script. Note that the reference reserved word can be dropped but in this case parenthesis are necessary.

Full form:

plot MyMACD = reference MACDHistogram;

Compressed form:

plot MyMACD = MACDHistogram();

The reference reserved word is required to distinguish the VWAP study from the vwap function, MoneyFlow study from the MoneyFlow function.

Calling the vwap function:

plot MyVWAP1 = vwap;

Referenicing the VWAP study:

plot MyVWAP1 = reference VWAP;

If the plot name is not defined, study's main plot should be referenced (main is the first declared in the source code). If parameters values are not defined, default values should be used. Inputs' names can be dropped only for thinkScript® studies, because they have fixed order of inputs in the code:

Full form:

plot MyBB2 = BollingerBandsSMA(price = open, displace = 0, length = 30);

Compact form:

plot MyBB =  BollingerBandsSMA(open, 0, 30);

Example

The following example references def variable instead of plot:

def st = ATRTrailingStop().state;
AssignPriceColor(if st == 1
then GetColor(1)
else if st == 2
then GetColor(0)
else Color.CURRENT);
def bs = !IsNaN(close) and ATRTrailingStop().BuySignal == yes;
def ss = !IsNaN(close) and ATRTrailingStop().SellSignal == yes;
AddVerticalLine(bs or ss, if bs then "Buy!" else "Sell!", if bs then GetColor(0) else GetColor(1));

First variable, st, is the reference to the state variable from the ATRTrailingStop study script; bs and ss are references to the BuySignal and SellSignal variables from the same study.