View Full Version : backtesting and DateTime.Now
12-27-2007, 12:38 PM
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?
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 which gives you bar time.
06-28-2010, 09:04 AM
Is the reverse also true? If I use Time 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) <= 113000 or ToTime(DateTime.Now) <= 113000 in my strategy when trading it live? If so, then we have to do something like
allowTrading = ToTime(Time) >= 60000 && ToTime(Time) <= 113000;
allowTrading = ToTime(DateTime.Now) >= 60000 && ToTime(DateTime.Now) <= 113000;
06-28-2010, 09:18 AM
They refer to different things and how you use will depend on what you want to express.
Time 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.