Welcome to Creating Custom Data Windows. This is a section for advanced users that will describe how to add your own data windows that will be used in training a machine learning model. For help with an introductory guide to creating a new machine learning model please see Creating a Machine Learning Model. 

Using this technique will override the default Deep Signal Library method of training a new machine learning model. The user will need to call methods to add in training data sets for long trades, short trades, and long and short trades that have failed to reach a profit target. If there are not substantial amounts of each type of data the model may not be trained correctly.

In order to create custom data windows, the Create Custom Training Data Sets property will need to be set to true. It can either be set in Strategy Analyzer under the Training Parameters section or in the OnStateChange method in your derived strategy where State == State.SetDefaults. Please note that setting the Create Custom Training Data Sets to true will override the default Deep Signal Library method for training machine learning models and the user will need to add their own training data sets.



The next step is to decide what training sets you would like to use for creating a model. The Deep Signal Library uses Supervised Learning and tries several different machine learning algorithms to create the best performing model. It does require the user to add training sets for long trades, short trades, and long and short trades that have failed to reach a profit target in order to train the model correctly.

Each training set will use the model parameter Pre Signal Window Size (window size) to determine how many bars of data we will use for each training set. The window size can be set anywhere from using only one bar of data to 50 bars of data. Please note that by using a larger number of bars of data the machine learning model may overfit the model for that data set. Please see the wikipedia page for overfitting for more info. Experimentation is recommended for finding an optimum window size for your data.

The Pre Signal Window is the window of data before the Signal Bar. The Signal Bar is the first bar in which the price moves up or down to reach a profit target. The Pre Signal Window identifies a window of data in which on the next bar we would want to enter a trade. Here is a chart that shows the Pre Signal Window in relation to the Signal Bar.



There are four methods we call in order to add a data set for training our model.

  • DSTAddLongDataWindow(int signalBarsAgo) - This method will add a data set to the long trade training data sets used when creating a machine learning model. Pass an integer as signalBarsAgo to let the library know how many bars ago the Signal Bar occurred. The default for signalBarsAgo is 0 bars, which is the current bar.
  • DSTAddShortDataWindow(int signalBarsAgo) - This method will add a data set to the short trade training data sets used when creating a machine learning model. Pass an integer as signalBarsAgo to let the library know how many bars ago the Signal Bar occurred. The default for signalBarsAgo is 0 bars, which is the current bar.
  • DSTAddFailedLongDataWindow(int signalBarsAgo) - This method will add a data set to the failed to reach a long profit target training data sets used when creating a machine learning model. Pass an integer as signalBarsAgo to let the library know how many bars ago the Signal Bar occurred. The default for signalBarsAgo is 0 bars, which is the current bar. These sets are used in creating a supervised machine learning model to let the model know when not to enter a long trade.
  • DSTAddFailedShortDataWindow(int signalBarsAgo) - This method will add a data set to the failed to reach a short profit target training data sets used when creating a machine learning model. Pass an integer as signalBarsAgo to let the library know how many bars ago the Signal Bar occurred. The default for signalBarsAgo is 0 bars, which is the current bar. These sets are used in creating a supervised machine learning model to let the model know when not to enter a short trade.



There are several different ways in which one could add their own training sets but here is a simple version. In the OnBarUpdate method called by NinjaTrader we will add a short data window in which we want the Deep Signal Library to use as a training set for Short Trades if the slow moving average crosses above a fast moving average. For the slow moving average crossing above a fast moving average we will also add a training set for failed to reach long profit targets. 


We will also add a data window for long trades and failed to reach short profit targets when the slow moving average crosses below the fast moving average.


Here is the code example:


            protected override void OnBarUpdate()

               {

                       // Please do not change, the DST Library will need to call OnBarUpdate. Add any additional code below this line.

                       base.OnBarUpdate();


                       if (CrossAbove(SMA(slowSMA), SMA(fastSMA), 1))

                       {

                               DSTAddShortDataWindow(0);

                               DSTAddFailedLongDataWindow(0);

                       }

                       else if (CrossBelow(SMA(slowSMA), SMA(fastSMA), 1))

                       {

                               DSTAddLongDataWindow(0);

                               DSTAddFailedShortDataWindow(0);

                       }                        

               }



There are many different ways we can create our own training data sets, but it is important that there is some correlation from our indicator data that is fed into the model and our training data sets. In the example, there is no correlation but it is intended for illustration purposes only and not meant to be a viable trading strategy.


In order to train the model correctly we need to have data sets for successful long and short trades as well as long and short trades that failed to reach their profit target. In supervised learning, the model expects to have both types of data sets in order to learn what is the correct data to use to enter a trade.


Please notice when we call the different DST methods, such as DSTAddShortDataWindow(0) we are passing a 0. That means that we would like to use the current bar as the Signal Bar. The actual data window size (in bars) that gets passed as a training set will be based on the Pre Signal Window Size parameter. The bar just before the Signal Bar is the last bar in the data window. The first bar in the data window will be the last bar minus how many bars are set in Pre Signal Window Size plus one. 


The data window will be used to try and predict when to enter a trade such that if we enter a trade at the Signal Bar it will hit our long or short profit target within the Bars To Target number of bars.







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.