Welcome to Programming Your Machine Learning Strategy. This section will describe how to use the Deep Signal Library for programming a new machine learning strategy. For help with installing the DS Library please click on the Installation Guide. 

The first step is to make sure we have compiled the strategies after installation. From NinjaTrader, click on the menu item New -> NinjaScript Editor. When the NinjaScript Editor window opens we need to compile the strategies. Press F5 or click on the Compile button.



 

There are several Deep Signal strategy files under the DST folder.

  • DSTCreateCustomDataWindow is derived from DSTCreateModelBase. This is an example file for creating a new machine learning model strategy using custom data windows. Please see Creating Custom Data Windows for more information.
  • DSTCreateCustomFeatureData is derived from DSTCreateModelBase. This is an example file for creating a new machine learning model strategy using custom feature data. Please see Adding Custom Feature Data for more information.
  • DSTCreateModelBase is the base strategy file for creating a new machine learning model. Please do not modify this file as it will be the base file for any new Deep Signal Technologies (DST) strategy file you create. 
  • DSTCreateModelTest is derived from DSTCreateModelBase. This is an example file for creating a new machine learning model strategy. You can either modify this file or create a new strategy file and use the DSTCreateModelBase as the parent.
  • DSTCreateMomentumModelTest is derived from DSTCreateModelBase. This is another example file for creating a new machine learning model strategy. You can either modify this file or create a new strategy file and use the DSTCreateModelBase as the parent.
  • DSTCreateCustomTraining is derived from DSTCreateModelBase. This is an example file for creating a new machine learning model strategy using custom training data. You can either modify this file or create a new strategy file and use the DSTCreateModelBase as the parent. Please note, this is for advanced users when wanting to create their own customized training data sets. Please see Creating Custom Data Sets for more information on creating customized data sets.
  • DSTPredictCustomDataWindow is derived from DSTPredictModelBase and is the strategy to make predictions for models that were created with DSTCreateCustomDataWindow.
  • DSTPredictCustomFeatureData is derived from DSTPredictModelBase and is the predictive strategy for DSTCreateCustomFeatureData.
  • DSTPredictModelBase is the base strategy for running the machine learning model either in a backtest or live. Please do not modify this file because it is needed by the DSTPredictModelTest and any new predictive machine learning model strategies that are created.
  • DSTPredictModelTest is derived from DSTPredictModelBase and can be modified to suit your needs or can be used as an example for creating a new predictive machine learning strategy.
  • DSTPredictMomentumModelTest is derived from DSTPredictModelBase and is the strategy to make predictions for models that were created with DSTCreateMomentumModelTest.
  • DSTUsingTwoModelsStrategy is derived from DSTPredictModelBase and is an example of using two machine learning models in a strategy.

We'll start with the DSTCreateModelTest strategy file. If we click on the DSTCreateModelTest strategy in the NinjaScript Editor window the C# code window will show the contents of the strategy file. We'll go over each of the numbered areas below.


 

  1. Each strategy that is used to create a new machine learning model using the DS Library must derive the strategy from DSTCreateModelBase. This is the base class that contains code to access the DS Library and will call methods needed to create the new model
  2. Each derived strategy from DSTCreateModelBase must override the OnStateChange method and call base.OnStateChange. 
  3. The AddDSTIndicator method is used to add indicator data to the machine learning model. This method is used in both creating a new model or using an existing model to predict long or short signals. Here is a link to more information about AddDSTIndicator. This method is where you can add whatever indicator data you would like to use in the machine learning model. As an example, if you wanted to add a moving average of the primary instrument, you could add AddDSTIndicator(SMA(20), "SMA-20", 2). This will add the Simple Moving Average of the primary instrument with a period of 20, indicator name is "SMA-20" and all data fed to the machine learning model will be rounded to 2 decimals. Please note that if you add indicator data for the create model strategy you will need to add the same indicator data in the same order to the predict model strategy.
  4. AddDSTInstrument is similar to AddDSTIndicator except that AddDSTInstrument will add instrument data to the machine learning model. Here is a link to more information about AddDSTInstrument.
  5. Each derived strategy from DSTCreateModelBase must override the OnBarUpdate method and call base.OnBarUpdate.

 

The easiest way to start to create your own machine learning model is modify the AddDSTIndicator methods and add whatever data is appropriate for your model. You will need to add your indicator data series to AddDSTIndicator.

As an example if you have a winning strategy that uses Momentum and Stochastics that you wanted to try in a machine learning model, you could add something like the following in the OnStateChange method: 

protected override void OnStateChange()
 
  // Please do not change, the DST Library will need to call OnStateChange
  base.OnStateChange();   

  if (State == State.Configure)
  {
     // AddDSTIndicator adding Momentum with a period of 20
     AddDSTIndicator(Momentum(20), "Momentum", 2);

     // AddDSTIndicator adding Stochastics.D value for PeriodD=7, PeriodK=14 and Smooth=3
     AddDSTIndicator(Stochastics(7, 14, 3).D, "Stochastics(7, 14, 3).K", 2);
   }
 }

 

For a list of NinjaTrader system indicators that can be used please see the following NinjaTrader link: System Indicator Methods

Once you have decided on what data you would like to feed into the machine learning model, the next step is to be sure your code compiles. Press the F5 key or click on the Compile button to compile your code. If there are any errors, you will need to fix them before going on to the next step.

If your code compiles then lets go on to the next step of Creating A Machine Learning Model.






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.