How Scripts Work: Difference between revisions
From MultiCharts
→How Orders Are Sent Depending on the Last Bar Status
(8 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
PowerLanguage studies can be used with the charts created by the MultiCharts trading platform and with the Portfolio | PowerLanguage studies can be used with the charts created by the MultiCharts trading platform and with the Portfolio Trader. | ||
PowerLanguage studies operate on price data, organized as a series of data points, based on a defined interval and arranged in a chronological order. Each data point is a summary of a group of price points (ticks) that includes the price values of the first and of the last tick, as well as the range of price movement over the defined interval. Data points also include additional data, such as date and time of the last tick and trade volume. | PowerLanguage studies operate on price data, organized as a series of data points, based on a defined interval and arranged in a chronological order. Each data point is a summary of a group of price points (ticks) that includes the price values of the first and of the last tick, as well as the range of price movement over the defined interval. Data points also include additional data, such as date and time of the last tick and trade volume. | ||
Line 7: | Line 7: | ||
In this guide, references to charts are used as a visualization tool to aid in understanding how the PowerLanguage scripting works. | In this guide, references to charts are used as a visualization tool to aid in understanding how the PowerLanguage scripting works. | ||
PowerLanguage studies are divided | PowerLanguage studies are divided into two main types: Indicators and Signals. | ||
An '''Indicator''' is a visual technical analysis tool, used to analyze market conditions and identify and forecast trends and market patterns. An indicator is a visualization of a mathematical formula, and consists of one or more '''Plots''' – lines, histograms, series of points or crosses, highs and lows, left and right ticks, or a combination of the above, displayed on a chart. Indicators are computed using only price, volume, and (occasionally) open interest data. | An '''Indicator''' is a visual technical analysis tool, used to analyze market conditions and identify and forecast trends and market patterns. An indicator is a visualization of a mathematical formula, and consists of one or more '''Plots''' – lines, histograms, series of points or crosses, highs and lows, left and right ticks, or a combination of the above, displayed on a chart. Indicators are computed using only price, volume, and (occasionally) open interest data. | ||
Line 90: | Line 90: | ||
A bar is considered completed when it is closed and no additional ticks can be added to it. | A bar is considered completed when it is closed and no additional ticks can be added to it. | ||
* For time-based charts, the bar is closed once the first tick with a time stamp past the bar's interval is received, or if no additional ticks are received for a period of | * For time-based charts, the bar is closed once the first tick with a time stamp past the bar's interval is received, or if no additional ticks are received for a period of 300 seconds. | ||
* For tick-based charts, the bar is closed once the defined number of ticks has been reached. | * For tick-based charts, the bar is closed once the defined number of ticks has been reached. | ||
* For range-based charts, the bar is closed once the tick with a price outside of the original bar's range has been received. | * For range-based charts, the bar is closed once the tick with a price outside of the original bar's range has been received. | ||
Line 97: | Line 97: | ||
<br> | <br> | ||
=== The Maximum number of bars a study will reference (Signals) === | === The Maximum number of bars a study will reference (Signals) === | ||
Line 103: | Line 104: | ||
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. | 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 | 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 for the signals should be set manually. | ||
To select the smallest '''MaxBarsBack '''value sufficient for a particular | To select the smallest '''MaxBarsBack ''' value sufficient for a particular strategy, set the value manually to the largest data offset across all signals applied to a given chart. | ||
Learn more about setting '''MaxBarsBack''' values for [[Strategy_Properties|Signals]] | Learn more about setting '''MaxBarsBack''' values for [[Strategy_Properties|Signals]] | ||
<br> | <br> | ||
=== Order Execution Priority === | === Order Execution Priority === | ||
Line 131: | Line 127: | ||
{| class="wikitable" | {| class="wikitable" | ||
|colspan="4"|'''Order Execution Priority Table''' | |||
|- | |- | ||
|colspan="4"|Higher value indicates greater priority | |||
|- | |- | ||
|'''Position'''||'''Flat'''||'''Long'''||'''Short''' | |'''Position'''|| '''Flat''' ||'''Long'''||'''Short''' | ||
|- | |- | ||
|'''Long Entry'''||'''1'''||'''1'''||''' | |'''Long Entry'''||''' 1 '''||''' 1 '''||''' 3 ''' | ||
|- | |- | ||
|'''Short Entry'''||'''1'''||''' | |'''Short Entry'''||''' 1 '''||''' 3 '''||''' 1 ''' | ||
|- | |- | ||
'''Long Exit'''||'''-'''||''' | |'''Long Exit'''||''' - '''||''' 2 '''||''' - ''' | ||
|- | |- | ||
'''Short Exit'''||'''-'''||'''-'''||''' | |'''Short Exit'''||''' - '''||''' - '''||''' 2 ''' | ||
|} | |} | ||
Line 193: | Line 189: | ||
The net result of executing the above orders, from a Short position, will be a Flat position. | The net result of executing the above orders, from a Short position, will be a Flat position. | ||
<br> | <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]] | [[Category:PowerLanguage]] |