NinjaTrader Strategy Modification (recommended)

A small code modification is required to NinjaTrader strategy scripts to ensure that tsSignalCopier can identify a specific instance of your strategy to track. A new string property is added called "Stratid", and a new variable called "stratid" is added to save the property value. The new "Stratid" property is used by tsSignalCopier to scan all of the running strategies for a special id property to match with a value that you set in both your strategy and tsSignalCopier.

A sample strategy that includes the modifications can be downloaded using the link that follows this article below.

Explanation:

  • The NinjaTrader environment allows multiple instances of the same strategies and symbols to be running at the same time
  • tsSignalCopier needs to find and connect to a specific strategy instance to deliver orders to the intended broker or trade publisher
  • The internal id assigned by NinjaTrader changes each time the system is restarted, so it is not reliable as an identifier

 

There are two minor changes required:

Modification 1/2:

Look for the line #region Variables, and add the line shown in bold below:

#region Variables

         private string stratid = "myStrategyId";

Modification 2/2:

Look for the line #region Properties, and add the lines shown in bold below:

#region Properties

        [Description("Id for StrategyXtender")]
        [GridCategory("Parameters")]
        public String Stratid
        {
            get {return stratid;}
            set {stratid = value;}
        }

  • Compile your strategy and check for errors.
  • Adding the modified strategy to a chart, and set the "Stratid" value to a unique value, such as "Momentum Breakout Strategy 1". 
  • Add the tsSignalCopier strategy to your chart, and change the "TargetStrategyId" value to match the value assigned in your strategy.

Monitor the Output window to confirm that tsSignalCopier has located the correct strategy instance.

If everything is working correctly, you should see output similar to the following in the NinjaTrader Log Window:

*NT** Enabling NinjaScript strategy 'tsSignalCopier/2a98fd1786064ffa8a04d686710c2502' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes
2018/04/16 19:23:49 Collective2:97790500 tsSignalCopier 0.9.4 for NT7: Starting link to StrategyXtender...
2018/04/16 19:23:49 Collective2:97790500 SUCCESS SignalCopier Link Connected to localhost:51201
2018/04/16 19:23:49 Collective2:97790500 Searching strategies...
Checking tsSampleStrategy Id c31ef3a1a5614dbda1e7c1b85af42915
Found Strategy with Stratid=tsSampleStrategyX
2018/04/16 19:23:49 Collective2:97790500 FOUND Strategy with Private Target Id tsSampleStrategyX (Strategy:tsSampleStrategy Symbol:ES 06-18 DataSeries:500 Tick)
2018/04/16 19:23:51 Collective2:12345678 Strategy:tsSignalCopier Status Change: Loaded
2018/04/16 19:23:51 Collective2:12345678 Strategy:tsSignalCopier Status Change: Loaded

 

Read 2017 times Last modified on Wednesday, 18 April 2018 08:40