Welcome to Using Multiple Models In Strategies. This section will describe how to use multiple machine learning models in a strategy. For help with an introductory guide to creating a new machine learning model with a single strategy, please see Creating a Machine Learning Model.
The first step in using multiple models with one strategy is making sure we have created a machine learning model for each of the models we would like to use. In our example, we need to create a model for the DSTCreateMomentumModelTest and DSTCreateModelTest strategies. Please see the Creating a Machine Learning Model for more information about creating an initial machine learning model for DSTCreateMomentumModelTest and DSTCreateModelTest.
After the models are created we'll use the DSTUsingTwoModelsStrategy Deep Signal strategy in our example. To view the DSTUsingTwoModelsStrategy strategy, please open the NinjaScript Editor by going to New -> NinjaScript Editor from the main Control Panel and double click on the DSTUsingTwoModelsStrategy strategy.
The strategy uses two indicators, DSTPredictIndicatorMomentum and DSTPredictIndicatorTest for long and short trade signals for each model. For more information on setting up the indicators, please see the Using Deep Signal Indicators section. Within the OnStateChange section of each indicator, you will need to add the indicator data you would like to use by calling the AddDSTIndicator method. The examples already have indicator data set up, but please feel free to modify to suit your needs. You will need to be sure that the indicator data that is used to predict a trade entry must match the indicator data that was used in the strategy to create the initial machine learning model.
For each indicator in the DSTUsingTwoModelsStrategy strategy, we need to pass which machine learning model we will use for the trade signals. Here are the indicators in the NinjaScript source code.
private DSTPredictIndicatorMomentum DSTPredictMomentum
return DSTPredictIndicatorMomentum(_LogMessagesStr, _BaseFolder, DSTDataFolderSelection,
_MomentumDataFolder, false, _GoLongBrushColor, _GoLongBrushColor);
private DSTPredictIndicatorTest DSTPredictTest
return DSTPredictIndicatorTest(_LogMessagesStr, _BaseFolder, DSTDataFolderSelection,
_TestDataFolder, false, _GoLongBrushColor, _GoLongBrushColor);
The properties that are passed into each indicator are set in the Properties region of code, along with some of them being set by the user in the Property Accessor's region. The _MomentumDataFolder and _TestDataFolder are the names of the folders for the Deep Signal models for each of indicators. These will get set by the user when adding the DSTUsingTwoModelsStrategy strategy.
The two indicators are used in the OnBarUpdate in DSTUsingTwoModelsStrategy to determine if we have a long or short signal for each model.
protected override void OnBarUpdate()
if (CurrentBar < BarsRequiredToTrade)
if (Position.MarketPosition == MarketPosition.Flat)
if (DSTPredictMomentum.GoLongSignal > 0)
EnterLong(_Shares, "Long Momentum");
else if (DSTPredictMomentum.GoShortSignal > 0)
EnterShort(_Shares, "Short Momentum");
if (DSTPredictTest.GoLongSignal > 0)
EnterLong(_Shares, "Long Test");
else if (DSTPredictTest.GoShortSignal > 0)
EnterShort(_Shares, "Short Test");
Each of the indicators provide a Series<double> data value that tells whether we should go long or go short for that model. The GoLongSignal will be 1 if the model predicts a Long Trade Entry Signal or 0 for no signal. Likewise for the GoShortSignal, the GoShortSignal value will be 1 if the model predicts a Short Trade Entry Signal or 0 for no signal. The  at the end of the GoLongSignal signifies we are looking at the current bar for the long signal. We could also look back at previous bars, for example, GoLongSignal will look 1 bar back for a long signal.
When initially adding the strategy to either a chart or the Strategies tab in the Control Center, the user will need to choose the appropriate model for each indicator. Clicking on the Strategies button at the top of the chart or right clicking in an open chart and selecting Strategies... will bring up a menu where we can choose the DSTUsingTwoModelsStrategy strategy.
Add the DSTUsingTwoModelsStrategy and then you will be able to change the parameter values for the strategy. You will need to choose a machine learning model that was created with DSTCreateModelTest for the Test Strategy Data Folder and choose a model that was created with DSTCreateMomentumModelTest to use with the Momentum Strategy Data Folder. You will need to add which instrument along with the data series type and any configure any additional parameters needed.
If the strategy was added to a chart, the Go Long Brush and Go Short Brush colors will draw the appropriate colored bar on the chart.
Once you are done, click on OK to add the strategy. If you added the strategy to a chart, you will be able to see the chart with multiple colored bars. The Indian Red colored bars are short trade entries from the Momentum Strategy and the Coral colored bars are from the Test Strategy. We can see a mixture of the two colors where both entries overlap on the same bar.
Having the colored trade entries on a chart for each strategy can help troubleshoot any trade entry issues we're seeing. We can also add other indicators to the chart that can potentially filter out any unwanted trade entries.
Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results.