Indicator scripts are used for calculating a series of numerical values based on the price, volume and open interest of an underlying symbol. Common use-cases include plotting them on a chart, displaying them as watchlist columns and using them to implement other scripts.


Setup


An Indicator script can be added to a chart using the chart's Indicators Window and it can be added to a watchlist using the watchlist's Script Columns Window. To use an Indicator script from a Trading Strategy script (or any other supported script) please see our sample Trading Strategy scripts that ship with the platform.


Functions


Name

Description

OnInitialize()

This function accepts the user parameters for the script and is called when a new indicator instance is created.

One of the parameters accepted by it must be that of a symbol or another script that is based on a symbol (drawing, indicator, pattern or signal). This symbol will be used as the underlying symbol for the indicator.


The parameter values can be specified from the user interface (UI) or from another script, depending on usage.

double OnBarUpdate()

This function is used for calculating the indicator value for the latest bar (see the Indicator functions).

OnChartSetup()

This function is used for setting up the indicator on the chart and registering its pens (see the IndicatorChartRegisterPen function).

byte OnSelectPen()

This function is used for selecting an indicator pen with which to color the latest indicator value. Call the IndicatorChartRegisterPen function from the OnChartSetup function in order to register an indicator pen.


Function Details


OnInitialize()

This function accepts the user parameters for the script and is called when a new indicator instance is created.

One of the parameters accepted by it must be that of a symbol or another script that is based on a symbol (drawing, indicator, pattern or signal). This symbol will be used as the underlying symbol for the indicator.


The parameter values can be specified from the user interface (UI) or from another script, depending on usage.


double OnBarUpdate()

This function is used for calculating the indicator value for the latest bar (see the Indicator functions).


Returns


The indicator value for the latest bar.


OnChartSetup()

This function is used for setting up the indicator on the chart and registering its pens (see the IndicatorChartRegisterPen function).


byte OnSelectPen()

This function is used for selecting an indicator pen with which to color the latest indicator value. Call the IndicatorChartRegisterPen function from the OnChartSetup function in order to register an indicator pen.


Returns


The indicator pen index to use for coloring the latest indicator value.