Define Setup Method

Initialize your data and indicators.

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.

Connecting to a data stream

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:

public override void Setup(DataMarketplace data, IndicatorsMarketplace indicators)
{
hourlyBars = data.Bars(BarPeriodType.Hour, 1).WithOffset(25);
}

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.

Connecting with indicators

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.

public override void Setup(DataMarketplace data, IndicatorsMarketplace indicators)
{
hourlyBars = data.Bars(BarPeriodType.Hour, 1).WithOffset(25);
smaSlow = indicators.SMA(25).OnSeries(hourlyBars.Close);
smaFast = indicators.SMA(10).OnSeries(hourlyBars.Close);
}

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:

using Signals.Indicators.SMA;
using Signals.DataSeries.Bars;
using Signals.Framework;
public class MyStrategy : SingleMarketStrategy
{
private Bars hourlyBars;
private SMA smaSlow;
private SMA smaFast;
public override void Setup(DataMarketplace data, IndicatorsMarketplace indicators)
{
hourlyBars = data.Bars(BarPeriodType.Hour, 1).WithOffset(25);
smaSlow = indicators.SMA(25).OnSeries(hourlyBars.Close);
smaFast = indicators.SMA(10).OnSeries(hourlyBars.Close);
}
public override void RegisterActions()
{
// method for registering actions over the data e.g. your strategy logic
}
}