The first thing I notice when I enable a strategy is that ninja trader appears to load previous data into the strategy (I can see "data loading" messages bottom right of control center.
My main concern is what exactly is pushed through my strategy code at startup, as this will effect my initialisation, etc, and potentially trades starting up.
From previous posts, I learned about the "Historical" flag. My understanding of this, is when this is true, this means that previous data is being supplied to the onBarUpdate function, ie: not current real time data.
With this in mind, I have the following at the beginning of the function:
protected override void OnBarUpdate() { // check if we are in a live data scenerio when running live, so we don't execute trades from prior days load. if ( isLiveStrat && Historical) return; ... ..
With the above code, my understanding is that when the initial data is loaded to the strategy when you enable it (as described above), this code above will cause the function to return immediatially, as this is historical data.
However, my testing reveals something else going on that I cannot explain. I have a print statement that executes each 60 mins printing a "." to the output window just so I know my code is still executing.
For some reason when I enable the strategy I get the following output (there's actually many more lines, but I've included just a few for reference):
**NT** Enabling NinjaScript strategy 'ASVSATest5-3b/6f7e37edeee1492b82fcfbd8d3b885e3' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes 3b-$AUDUSD - 24/04/2013 21:36:00: . 3b-$AUDUSD - 24/04/2013 23:29:00: . 3b-$AUDUSD - 25/04/2013 00:51:00: . 3b-$AUDUSD - 25/04/2013 01:54:00: . 3b-$AUDUSD - 25/04/2013 02:57:00: . 3b-$AUDUSD - 25/04/2013 04:12:00: . 3b-$AUDUSD - 25/04/2013 05:27:00: . 3b-$AUDUSD - 25/04/2013 06:34:00: . 3b-$AUDUSD - 25/04/2013 07:43:00: . 3b-$AUDUSD - 25/04/2013 08:53:00: . 3b-$AUDUSD - 25/04/2013 10:00:00: . 3b-$AUDUSD - 25/04/2013 11:07:00: . 3b-$AUDUSD - 25/04/2013 12:17:00: . 3b-$AUDUSD - 25/04/2013 13:22:00: . 3b-$AUDUSD - 25/04/2013 14:25:00: . 3b-$AUDUSD - 25/04/2013 15:42:00: . ... .. 3b-$AUDUSD - 15/05/2013 19:18:00: . 3b-$AUDUSD - 15/05/2013 20:24:00: . 3b-$AUDUSD - 15/05/2013 21:31:00: . 3b-$AUDUSD - 15/05/2013 22:42:00: .
As can be seen the print statements are executing each hour for data back the past 10 days. This data must be coming into my onBarUpdate function past the above code that I think should stop this.
To note: the above print messages all occur within one minute of enabling.
Also, the following code does the printing in the onBarUpdate function (on 1 minute bar update):
if ((BarsInProgress == MAIN_INDEX_ASK) || // minute/tick ASK data (BarsInProgress == 0) ) // (daily) { .. .. // print notifications notifyMinsCount++; if (isLiveStrat && (notifyMinsCount > notifyMins)) { notifyMinsCount = 0; Print(liveStratID + "-" + Instrument.FullName.ToString() + " - " + Time[0].ToString() + ": ."); } }
In my mind I should not be receiving these print messages, as the function should return immediately when past data for init. is loading.
Comment