MultiCharts | PowerLanguage Tutorials | CH1: How MultiCharts Executes Strategy

PowerLanguage and scripts

Strategy is instructions written in the programming language called PowerLanguage.
You need to use the PowerLanguage Editor to write the PowerLanguage instructions.
In the PowerLanguage Editor, these PowerLanguage instructions is called a script.
After you finish the write of script, you need to compile it (you can find compile (F3) in the PowerLanguage Editor).
The compilation will confirm whether the syntax of the instructions is correct, and translate it into the MultiCharts-executable instructions.
After the compilation is successful, the written script can be selected and executed in MultiCharts.

In the PowerLanguage Editor, there are three types of scripts: function, indicator and signal.
Open PowerLanguage Editor->File->Open a new file, to select the type of script to be written.

  • Function: Similar to functions in other programming languages, see Functions for details.
  • Indicator: Specifically for drawing(Ex: Plot), allowing you to draw visual line on the chart according to rules(Ex: 5MA) write in script.
  • Signal: Specifically for trade(Ex: Buy, Sell, Selltoshort, Buytocover), allowing you to send orders according to rules write in script.

The main differences between indicator scripts and signal scripts are:
Indicator scripts can execute drawing instructions, but cannot execute buy and sell instructions. You can execute the indicator script only, observe the changes of lines on the chart, and then manually place an order to buy or sell.
Signal scripts can execute buy and sell instructions, but cannot execute drawing instructions.

Script execution mechanism

When trading subjectively, if you use the strategy of buying with the golden cross of 2 moving averages, how do you judge to buy?
You will keep staring at the chart that is constantly receiving the market, watching the K bars run one by one, and then “constantly” checking whether the current 2 moving averages have a golden cross to judge whether to buy.
Yes, maybe not conscious, but as the market continues to receive, you are constantly repeating the logic of the strategy: check whether the current 2 moving averages have a golden cross to determine whether to buy.

The execution of script of MultiCharts is the same concept. As the market is continuously received, MultiCharts will continuously re-execute the script.
However, the re-execution does not mean that the next execution is carried immediately after previous one finished.
MultiCharts defines execution rules to determine when to start execution.
The execution rules of the indicator script and the signal script are different from each other. The respective rules are as follows:

Indicator

  • For the bars that have been completed in the past, the script is executed at the end of each bar (bar by bar).
  • If all completed bars have been executed the script, for the current incomplete bar, the script will be executed every time a tick is received (tick by tick), instead of waiting until the current bar is completed.

Completed Bars (Indicators)

When a bar meets the following conditions, it will be judged completed.

  • Time-based chart: If the first tick with the time stamp exceeding the time interval defined by the bar is received, it is determined that the bar completed.
    Or if no additional ticks are received for more than 3 seconds, it is also determined that the bar completed.

Signal

  • For the bars that have been completed in the past, the script is executed at the end of each bar (bar by bar).
  • If all completed bars have been executed the script, for the current incomplete bar, the script will NOT be executed until the current bar is completed.

Completed Bars (Signals)

When a bar meets the following conditions, it will be judged completed.

  • Time-based chart: If the first tick with the time stamp exceeding the time interval defined by the bar is received, it is determined that the bar completed.
    Or if no additional ticks are received for more than 300 seconds, it is also determined that the bar completed.

Reference

https://www.multicharts.com/trading-software/index.php/How_Scripts_Work

Leave a Reply