×

Sign up and get MultiCharts free

Use its powerful simulation mode with data included out of the box. Just fill out the form and start honing your trading skills with a few clicks.

Changes - MultiCharts

Changes

Jump to navigation Jump to search

How Scripts Work

1,281 bytes added, 12:29, 19 October 2021
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 for the signals should 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. The process of automatic '''MaxBarsBack '''detection may cause some functions to be executed repeatedly for the first few bars of a chart when a study is first applied; this can be avoided by setting the '''MaxBarsBack ''' value manually. To select the smallest '''MaxBarsBack '''value sufficient for a particular studystrategy, set the value manually. The recommended initial '''MaxBarsBack '''value is 50to the largest data offset across all signals applied to a given chart.
Learn more about setting '''MaxBarsBack''' values for [[Strategy_Properties|Signals]]
<br>
 
=== Order Execution Priority ===
|'''Position'''|| '''Flat''' ||'''Long'''||'''Short'''
|-
|'''Long Entry'''||''' 1 '''||''' 1 '''||''' 2 3 '''
|-
|'''Short Entry'''||''' 1 '''||''' 2 3 '''||''' 1 '''
|-
|'''Long Exit'''||''' - '''||''' 1 2 '''||''' - '''
|-
|'''Short Exit'''||''' - '''||''' - '''||''' 1 2 '''
|}
The net result of executing the above orders, from a Short position, will be a Flat position.
<br>
 
=== How Orders Are Sent Depending on the Last Bar Status ===
Three collections of orders are filled on each calculation: This Bar Close, Next Bar Market, Next Bar Price.<br>
If the last bar status of the base data series is closed (2 or -1) — This Bar Close orders are sent.<br>
If the last bar status of the base data series is opened (0 or 1) — Next Bar Market, Next Bar Price orders are sent.<br>
After the batch of orders is sent, it is cleared and will be filled only at the next calculation.<br>
<div style="background-color: #E5F6FF;">Tip: It is possible to view bar statuses (bar status from the chart, not from the script is meant) with the help of an indicator that updates on every tick..</div>
 
'''Examples'''<br>
 
''Situation 1''<br>
''2 and 2, where the number stands for the bar status from the script.''<br>
Only This Bar Close orders are sent if there are no new bars on the chart by this moment.<br>
If there is the new bar on the chart by this moment, Next Bar Market, Next Bar Price orders will be sent next.<br>
 
''Situation 2''</br>
''2 and 1''<br>
Only This Bar Close orders are sent if there are no new bars on the chart by this moment.<br>
If there is the new bar on the chart by this moment, Next Bar Market, Next Bar Price orders will be sent next.<br>
''1 and 2''<br>
Nothing is sent until the bar of the base data series is closed.<br>
 
''Situation 3''<br>
''1 and 2''<br>
Nothing is sent.<br>
''2 and 1''<br>
Only This Bar Close orders are sent if there are no new bars on the chart by this moment.<br>
If there is the new bar on the chart by this moment, Next Bar Market, Next Bar Price orders will be sent next.<br>
 
''Situation 4''<br>
''1 and 2''<br>
Nothing is sent.<br>
''2 and -1''<br>
Only This Bar Close orders are sent if there are no new bars on the chart by this moment.<br>
If there is the new bar on the chart by this moment, Next Bar Market, Next Bar Price orders will be sent next.<br>
[[Category:PowerLanguage]]

Navigation menu