Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Automated switch between summer time and winter time at two different time zones

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

    Automated switch between summer time and winter time at two different time zones

    Hello,

    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

    #2
    I believe the problem is that the US Times and European Times do not change on the same date. There are a few weeks where the US will be in DST before Europe switches to Summer hours, and a few weeks where Europe has switched back to standard time before the US does. This results in a 6 hour difference instead of a 7 hour difference.

    Please reference the following link for the current dates and let me know if this does not line up with what you're seeing with your method output:

    MatthewNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    647 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    367 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    571 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X