I programmed a method for my strategy which compares the "Central Standard Time" time and the "Central European Time" as I don't want to change manually parameters regarding the time on my ninjatrader strategy if there are discrepances occured because of winter time and summer time changes at the time zones. The problem is that during some bars the difference between this two timezones is not 7 hours like expected but 6 hours during the intra day trading day which I do not understand as summer time and winter time changes only twice a year?
Here is the code as follows:
private void timecheck()
{
DateTime cetTime = DateTime.Now;
DateTime timeUtc = DateTime.UtcNow;
try
{
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);
Print("cstTime: " + cstTime);
Print("cetTime: " + cetTime);
TimeSpan ts1 = cstTime - cetTime;
Print("TimeSpan : " + ts1);
Print("ts1: " + ts1.Hours); //Sometimes an output of 6 hours instead of 7 hours occurs! Why?
if (ts1.Hours != -7)
{
//Do something...
}
}
catch (TimeZoneNotFoundException)
{
Print("The registry does not define the Central Standard Time zone.");
}
catch (InvalidTimeZoneException)
{
Print("Registry data on the Central STandard Time zone has been corrupted.");
}
}
Any idea what the mistake is?
Thanks.
Rob
Comment