script

Syntax

script <script_name> { <script_code>; }

Description

This reserved word is used to define new scripts you may need to reference later on within a certain study or strategy.

Example

script MyEMA {
input data = close;
input length = 12;
def EMA = compoundValue(1, 2 / (length + 1) * data + (length - 1) / (length + 1) * EMA[1], Average(data, length));
plot MyEma = EMA;
}

declare lower;

plot Osc = MyEMA(close, 25) - MyEMA(close, 50);

This code defines the MyEma script where the first EMA value is calculated as SMA in contrast to the ExpAverage function whose first value is assigned the closing price. The main section of the code creates an oscillator based on the MyEMA difference for different lengths.