Changes

Jump to navigation Jump to search

How Scripts Work

7 bytes added, 16:51, 23 February 2012
The purpose of indicators is to plot visualizations of mathematical formulas on a chart. The plots are created based on one or more price data series.
When applied to a chart, an indicator script first evaluates all the [[#Completed Bars (Indicators)|completed bars]] one-by-one, starting with the very first (oldest) bar on the chart.  The entire script is executed once for each completed bar. On each bar, based on the results of the evaluation, an indicator script can generate output - graph, text, plot color change, audio alert, etc.
If indicator script contains references to previous bars' values, indicator can begin generating output starting with the first bar that follows the [[#Maximum number of bars a study will reference (Indicators)|Maximum number of bars a study will reference]].
Once all the completed bars on the chart have been evaluated, an indicator script will proceed to evaluate the last bar on the chart on tick-by-tick basis, without waiting for the bar to be completed. An incomplete bar is a summary of all ticks received since the previous bar was completed.  Each time a new tick is received, the entire script will be executed for that bar, until the bar is completed and the next bar is started. Indicator scripts treat incomplete bars the same way as the bars that are completed, and can take action each time an incomplete bar is evaluated.
Please note that only the last, incomplete, bar is re-evaluated on every new tick, and not the whole series.
A study's script can refer to the values of previous bars for use in evaluation of the current bar.
When a value of a bar '''N''' bars ago is referenced in a script, the study can only be visualized starting with the '''N + 1''' bar.  The number of previous bars that must be available for a script in order to start performing calculations is called '''Maximum number of bars a study will reference''', or '''MaxBarsBack'''. The '''MaxBarsBack''' value can be selected to be detected automatically or set manually.
When detected automatically, '''MaxBarsBack '''will initially be set to the value of the largest data offset in the study; however, if a variable data offset is used in the script, the initial '''MaxBarsBack ''' value may prove to be too small. In such a case, the '''MaxBarsBack '''value will automatically be increased by 5 or by a factor of 1.618, whichever yields a higher value, and the study recalculated.
<br>
 
== Signals ==

Navigation menu