Execution Model

Just like a classic strategy's Entry/Exit rules, the code comprising a QuantScript strategy is executed whenever a bar opens.

A bar is a summary of an instrument's price movement over some period of time. It is comprised of 5 data points - the opening price of the time period (the first price), the highest price reached during the time period, the lowest price reached during the time period, the closing price of the time period (the last price) and the volume (number of trades during the time period).

When you backtest a QuantScript strategy, your code will be executed as many times as the amount of Max Data Bars you have configured your strategy with, from the right panel.

However, there are two caveats to the statement above:

  1. Your code could execute fewer times than the configured Max Data Bars if we don't actually have that many bars in our database. For example, if you choose a 1-day Trading Frequency and 200,000 Max Data Bars - well, we obviously don't have 548 years' worth of backtesting data.
  2. Your code always executes an additional, constant, 500 times. This is part of a warmup period, which will be covered later.

In contrast, when you run a QuantScript strategy, your code will be executed once every 1 minute, 5 minutes, 10 minutes, 15 minutes, 30 minutes, 1 hour, 4 hours or 1 day, depending on your strategy's Trading Frequency.

Each time your code executes, a signal may be produced and an action may be taken, according to the Signal Condition Statements.

For example, if you backtest your Hello, World! strategy with 1000 Max Data Bars, the code will be executed 1000 times, and there will be ~500 opened positions for the duration of the backtest (why 500?).

This pretty much covers the execution model of QuantScript. As you can see, each execution of the code is tied to a specific data bar. Next, we will look at how to access the data points of this bar.