Welcome to the Adding Custom Feature Data section. This is for advanced users and will describe how to add your own feature data 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 allow the user to add their own custom feature data bar by bar into a strategy for creating a new machine learning model. They will need to add the same data bar by bar when doing a prediction. Using this method will override using the AddDSTIndicator method for adding data to the model.
In order to add custom feature data, the user will call the DSTRegisterCustomData method in OnStateChange when State == State.Configure. This method will let the Deep Signal Library know that the user wants to add their own feature data bar by bar in OnBarUpdate. Here is an example of where to use the DSTRegisterCustomData method. It is in the example strategy file DSTCreateCustomFeatureData.
protected override void OnStateChange()
if (State == State.SetDefaults)
Description = @"Prediction strategy for using custom feature data";
Name = "DSTPredictCustomFeatureData";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
else if (State == State.Configure)
DSTRegisterCustomData("Slow SMA", 2);
DSTRegisterCustomData("Fast SMA", 2);
In the example above we are registering 3 custom features. The parameters are the name, which must be a string and the number of decimal points of precision for the value. There is an optional method that overrides the minimum and maximum values for the feature when doing normalization.
The next step is to add our custom feature data in the OnBarUpdate method. The DSTSetCustomData method will set custom feature data for the feature that was registered with DSTRegisterCustomData. When calling the DSTSetCustomData we need to pass the same name that was registered along with the value.
protected override void OnBarUpdate()
// DST Library - The base OnBarUpdate needs to be called for updating the machine learning model data
DSTSetCustomData("Slow SMA", SMA(slowSMA));
DSTSetCustomData("Fast SMA", SMA(fastSMA));
If the user is using the custom feature set then the Deep Signal Library will ignore the AddDSTIndicator method. They can't be combined at this point in time.
The DSTIsValidLongDataSet and DSTIsValidShortDataSet override methods are both available using custom feature data. Both methods will allow the user to ignore data sets that don't meet whatever criteria the user decides.
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.