PDA

View Full Version : backtesting and DateTime.Now


andrewbee
12-27-2007, 12:38 PM
Hi,

In a strategy that uses DateTime.Now to get the current time, is this simulated in a backtest to be the correct time for the current bar?

Thanks

NinjaTrader_Ray
12-27-2007, 12:41 PM
No since DateTime.Now is a .NET property, NT has no wrapper logic around that. If you want relative time you need to access Time[0] which gives you bar time.

shodson
06-28-2010, 09:04 AM
Is the reverse also true? If I use Time[0] in my strategy will it not work, and I should use DateTime.Now instead? For example, if I don't want to allow trading after 11:30am, should I check that ToTime(Time[0]) <= 113000 or ToTime(DateTime.Now) <= 113000 in my strategy when trading it live? If so, then we have to do something like


if (Historical)
allowTrading = ToTime(Time[0]) >= 60000 && ToTime(Time[0]) <= 113000;
else
allowTrading = ToTime(DateTime.Now) >= 60000 && ToTime(DateTime.Now) <= 113000;
????

NinjaTrader_RyanM
06-28-2010, 09:18 AM
Hello Shodson,

They refer to different things and how you use will depend on what you want to express.

Time[0] refers to the time stamp of a bar. It is the time that the bar has ended or is projected to end.

DateTime.Now will capture your system clock at the moment of time the code is processed.