PDA

View Full Version : Detecting live or non live mode (replay/back testing)


BillCh
06-17-2009, 06:43 AM
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


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


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

NinjaTrader_Bertrand
06-17-2009, 07:01 AM
To check whether it's running on realtime or historical data, you can work with Historical() - http://www.ninjatrader-support.com/HelpGuideV6/Historical.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.

BillCh
06-18-2009, 07:43 AM
Good thoughts. Thx for the hints.