Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Comparing Timezones and drawing lines

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

    Comparing Timezones and drawing lines

    I'm having some trouble with getting a grasp on how NT8 handles time zone differences. For instance, I have two different versions of code below. And when this code is ran on a computer that has NT8 running on a different time zone than the time zone of the PC, I get some interesting results. My aim is to start drawing a line when the times[1][0] is at a specific time. The first one draws a line at a totally different time, and the second draws the line at the correct time, but to me, the code should do the same for either instance. Where am I going wrong in the first instance?

    Also, a second question, If my PC is in a timezone that has a different Daylight Saving Time than that of the exchange I am trading, is there a way to check the DST of the exchange timezone, and not the DST of my PC timezone? I haven't found something that can give me that in the NT8 reference, I'm probably missing something obvious.

    Notes:
    DSTSH- Specific starting hour depending on if we are in DST or not.
    DSTEH- Specific ending hour depending on if we are in DST or not.

    Code 1:
    Code:
    Currenttime = Times[1][0];
    CurrentTime = Currenttime.ToUniversalTime().TimeOfDay;
    
    if(CurrentTime.CompareTo(new TimeSpan(DSTSH,0,0)) > 0 && CurrentTime.CompareTo(new TimeSpan(DSTEH,5,0)) < 0 && DS == 0)
    {
    Do some calculations
    }
    
    // check for 5 mins after the end hour is past
    if(CurrentTime.CompareTo(new TimeSpan(DSTEH,5,0)) == 0)
    {
    StartTime = Times[1][0];
    EndTime = StartTime.AddHours(8);
    Draw.Line(this, "Line"+CurrentBar, false, StartTime, orangeLine, EndTime,orangeLine, OC, OL, OS,true);    
    }
    Code 2:
    Code:
    CurrentTime = Times[1][0];
    if ( CurrentTime.AddHours(HoursFromEST*-1).ToUniversalTime().Hour >= DSTSH && CurrentTime.AddHours(HoursFromEST*-1).ToUniversalTime().Hour <= DSTEH && DS == 0)
    {
    Do some calculations
    }
    
    // check time has passed the end hour
    if (CurrentTime.AddHours(HoursFromEST * -1).ToUniversalTime().Hour == DSTEH && CurrentTime.ToUniversalTime().TimeOfDay.Minutes == 0)
    {
    StartTime = CurrentTime;
    EndTime = StartTime.AddHours(8);
    Draw.Line(this, "Line"+CurrentBar, false, StartTime, orangeLine, EndTime,orangeLine, OC, OL, OS,true);
    }

    #2
    Hello Omegaknight,

    Thanks for your post.

    Each instrument has a Trading Hours template assigned to it that described the timezone of the exchange and trading hours for the exchange.

    When data is requested the timestamps of the data requested will be translated from the timezone entered in the default Trading Hours template to the timezone configured in the platform.

    If you change the timezone on the platform, the data is not changed and will need to be reloaded.

    Answering your initial question would require running tests and use debugging prints when testing in different timezone environments to see what evaluates differently, but I do not think it would be the path forward to take.

    If you want to use the times of the exchange, and get information from the Trading Hours template so your script can work with exchange based times, consider using a SessionIterator.

    SessionIterator - https://ninjatrader.com/support/help...oniterator.htm

    We look forward to assisting.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    597 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    555 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X