Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Understanding what NT does when enabling a real time strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Understanding what NT does when enabling a real time strategy

    I'm trying to understand what is happening when I enable a real time strategy.

    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:

    Code:
            
    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; 
    			
    ...
    ..
    For reference, "isLiveStrat" is a bool variable I set to true on my live strategies.


    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):


    Code:
    **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):

    Code:
    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.
    Last edited by PolarBear; 05-15-2013, 06:07 PM. Reason: formatting

    #2
    If you post a complete working sample, with your main logic removed, it would be easier to see what you are doing(and what mistakes there might be).




    Originally posted by PolarBear View Post
    I'm trying to understand what is happening when I enable a real time strategy.

    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:

    Code:
            
    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; 
    			
    ...
    ..
    For reference, "isLiveStrat" is a bool variable I set to true on my live strategies.


    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):


    Code:
    **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):

    Code:
    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


      #3
      PolarBear, your understanding about Historical is correct - if OnBarUpdate() is called for historical data this would be true, else false.

      How many days are you loading this script with per default? Would it be enough to cover BarsRequired for all series involved here?
      BertrandNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by elirion, Today, 01:36 AM
      0 responses
      3 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by gentlebenthebear, Today, 01:30 AM
      0 responses
      2 views
      0 likes
      Last Post gentlebenthebear  
      Started by samish18, Yesterday, 08:31 AM
      2 responses
      9 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by Mestor, 03-10-2023, 01:50 AM
      16 responses
      389 views
      0 likes
      Last Post z.franck  
      Started by rtwave, 04-12-2024, 09:30 AM
      4 responses
      33 views
      0 likes
      Last Post rtwave
      by rtwave
       
      Working...
      X