Define Setup Method
Initialize your data and indicators.
Last updated
Initialize your data and indicators.
Last updated
Now, let’s initialize our variables using the Setup method to define the data and indicators to be used. In this case, it will be the simple moving averages (SMA) and data sources that will be used to calculate technical indicator values.
The DataMarketplace object is an argument of the Setup method and you can use it in connecting your strategy to a data stream from the data marketplace which you want to use.
Intellisense is built into Signals online development environment and it will help you during the process of defining your strategy.
In our case, we want hourly bars, so we will use BarPeriodType.Hour. The setup method, after we have connected our strategy to a data stream based on hourly bars, will look like this:
The variable hourlyBars now contains historical pricing data with a 1 hour time-period. We are now able to receive hourly bars data in our strategy by simple indexing, starting from 0.
hourlyBars[0] — will get us a bar for the current hour
hourlyBars[5] — will get us a bar from 5 hours ago
WithOffset(25) means that our Bar variable will store values from up to 25 bars back. If our strategy needs to have access to older price values, we would need to increase the offset. Each price bar contains values for open, high, low, close, and volume for that specific period.
We already selected that we want to use SMA indicators when we defined our variables through the user interface. Now, let’s define the time period which we want to use for our SMAs and on which data stream we want to use them.
The smaSlow variable contains the values of the Simple Moving Average indicator with a period of 25, calculated from hourly prices. The smaFast variable contains the values of the Simple Moving Average indicator with a period of 10, calculated from hourly prices. We can easily access the values of SMA through the indexing mechanism, so when we want to receive the value of smaFast for the current hour — smaFast[0] — will do the job.
Here’s how the code looks once we set our variables and connect the strategy to hourly data and SMA indicators: