Pattern scripts are used for recognizing and highlighting chart patterns 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


A Pattern script can be added to a chart using the chart's Patterns Window and it can be added to a watchlist using the watchlist's Script Columns Window. To use a Pattern 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 pattern 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 pattern.


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

int OnBarUpdate()

This function is used to determine whether a pattern match exists in which the latest bar is the last bar of the pattern.


If such a pattern match is found, the function returns the number of bars in the pattern, otherwise it returns zero.


Function Details


OnInitialize()

This function accepts the user parameters for the script and is called when a new pattern 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 pattern.


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


int OnBarUpdate()

This function is used to determine whether a pattern match exists in which the latest bar is the last bar of the pattern.

If such a pattern match is found, the function returns the number of bars in the pattern, otherwise it returns zero.


Returns


The total number of bars in the pattern ending at the latest bar (or zero if the pattern is not found).