Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Detecting live or non live mode (replay/back testing)

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

    Detecting live or non live mode (replay/back testing)

    How can my script detetct whether it runs in live trading or in replay resp. back testing mode?

    For real time trading I have set time restrictions like

    Code:
     
    if ( (alsoOutsideRegularHours == false && ToTime(DateTime.Now) >= eStartTime && ToTime(DateTime.Now) < eStopTime) || (alsoOutsideRegularHours == true) )
    entryTimeOK = true;
    else
    entryTimeOK = false;
    When in replay mode or backtesting this does not work so I have then

    Code:
     
    if ( (alsoOutsideRegularHours == false && ToTime(Time[0]) > ToTime( 9, 30, 0) && ToTime(Time[0]) <= ToTime(14, 50, 0)) || (alsoOutsideRegularHours == true) )
    entryTimeOK = true;
    else
    entryTimeOK = false;
    As I continually develop my scripts so I dont want to always enter the code and comment out the one part and uncomment the other wheter I use it for life trading or testing.

    So is there a way to check for replay true/fals or back testing true/false, even with a trick?

    Thx

    #2
    To check whether it's running on realtime or historical data, you can work with Historical() - http://www.ninjatrader-support.com/H...istorical.html

    To check if you're in the 'Strategy Analyzer' for example, you can add an input that you can set to 'true' if you're working there and then check for this in your code.

    Comment


      #3
      Good thoughts. Thx for the hints.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      152 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      89 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      131 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      127 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X