Multiple Instruments/Periods

So far, the series

and any derivatives of theirs have referred to whatever dataset your strategy is configured to use.

A dataset is set of data bars for an instrument/period pair. For example, the dataset "Gold 1-hour" consists of 1-hour bars that describe Gold's price movements

For example, if you set your strategy's instrument to EUR/USD, and its trading frequency to 30 minutes, then the series

will refer to the opening price of EUR/USD for some 30-minute period.

Classic ProQuant strategies can only use data from a single dataset.

QuantScript strategies, on the other hand, can access multiple datasets, and quite easily, too. The only restriction is that you cannot access a dataset if its period is smaller than the Trading Frequency of your strategy. For example, if your strategy is set to execute every hour - 1 hour Trading Frequency - your code cannot access datasets with periods less than 1 hour.

Let's see how you can access other datasets in QuantScript:

First, we have to mention dataset identifiers. A dataset identifier is used to specify which dataset we want to use. We write it like this: instrument:period, for example Gold:1h (Gold 1 hour), EURUSD:30m (EUR/USD 30 minutes), Tesla:1d (Tesla 1 day) etc.

Now, all you have to do is prepend a dataset identifier whenever you create a variable and that variable will be initialized using data from that specific dataset.

Let's see some examples:

1 # Our strategy's instrument is EUR/USD
2 # Our strategy's trading frequency is 30 minutes
4 # Gold 30 minutes' current bar open price
5 Gold:30m gold30mOpen = open
7 # EUR/USD 1 hour's current bar open price
8 # If we don't specify an instrument, the strategy's instrument is assumed
9 1h eurusd1hOpen = open
11 # Tesla 30 minutes' current bar open price
12 # If we don't specify a period, the strategy's trading frequency is assumed
13 Tesla teslaOpen = open
16 # This works for indicators too, or any expression
17 Gold goldSMA = SMA(open, 14)
18 eurusdSMA = SMA(open, 14)
20 # We can check indicators for multiple datasets and implement some entry/exit logic around them
21 enter long when Rises(eurusdSMA) and Rises(goldSMA)

Lastly, keep in mind that while you can combine values from different datasets, by, for example, adding them together, you cannot use time travel on a value which is based on multiple datasets. This would probably break the space-time continuum, so we've disallowed it.

Here's an example:

1 Gold:30m goldSMA = SMA(open, 14)
2 Tesla:4h teslaSMA = SMA(open, 14)
4 # This is perfectly fine
5 multiDatasetValue = goldSMA + teslaSMA # -> some number
7 # QuantScript doesn't know how to do this
8 # Do we go back 30 minutes? Or 4 hours?
9 # Instruments have different market hours, too
10 multiDatasetValuePrevBar = multiDatasetValue[1] # -> unknown

This pretty much covers the usage of multiple datasets in a single strategy.