Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 lakman184, 03-24-2024, 01:30 PM
    6 responses
    33 views
    0 likes
    Last Post morpheus0  
    Started by DawnTreader, 05-08-2024, 05:58 PM
    20 responses
    79 views
    0 likes
    Last Post DawnTreader  
    Started by llanqui, Yesterday, 10:29 AM
    5 responses
    25 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by lorem, 04-25-2024, 09:18 AM
    14 responses
    60 views
    0 likes
    Last Post lorem
    by lorem
     
    Started by TAJTrades, Today, 11:03 AM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Working...
    X