Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Convert market time to local time (time shift)

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

    Convert market time to local time (time shift)

    Hello, I want to show the market opening on the chart.

    But there is the time difference and I want to take that into account automatically.


    Future ES Open at 09:30

    28.10.2022 in Germany 15:30
    04.11.2022 in Germany 14:30​


    PHP Code:
    if("02.11.2022 09:30:00" == Time[0].ToString())
    {
        // Future ES Open at 09:30
        // DateTime.Now
    
        // 28.10.2022 in Germany 15:30
        // 04.11.2022 in Germany 14:30
        Print("Time[0] " + Time[0]);
    
        // TimeZoneInfo.Local (UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien
        Print("TimeZoneInfo.Local " + TimeZoneInfo.Local);
        // (UTC-06:00) Central Zeit (USA & Kanada)
        Print("Bars.TradingHours.TimeZoneInfo " + Bars.TradingHours.TimeZoneInfo);
    
        DateTime dateTime = Time[0];
    
        Print("TimeZoneInfo.Local.GetUtcOffset(dateTime)" + TimeZoneInfo.Local.GetUtcOffset(dateTime));
    
        // dateTime = dateTime.AddDays(-14);
        // dateTime 1 02.11.2022 09:30:00 (correct)
        Print("dateTime 1 " + dateTime);
        dateTime = dateTime.Add(-Bars.TradingHours.TimeZoneInfo.GetUtcOffset(dateTime));
    
        // dateTime 2 02.11.2022 14:30:00 (correct)
        Print("dateTime 2 " + dateTime);
    
        // Test 2
        dateTime = Time[0];
    
        // ConvertTime 1 02.11.2022 15:30:00 not right
        Print("ConvertTime 1 " + TimeZoneInfo.ConvertTime(dateTime, Bars.TradingHours.TimeZoneInfo, TimeZoneInfo.Local));              
    }
    ​ 
    



    How can I set the right opening time depending on the market. At ES 9:30 correctly in the current time on the chart?


    I would appreciate any help or advice.
    Last edited by 1001111; 11-03-2022, 08:27 PM.

    #2
    Have you considered using the SessionIterator?


    Comment


      #3
      Unfortunately this is not possible

      Comment


        #4
        I have the solution.
        According to CME it is ET time and not UTC.

        HTML Code:
        var easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
        and

        HTML Code:
        TimeZoneInfo.ConvertTime(Time[0], TimeZoneInfo.Local, easternZone);

        Comment


          #5
          Hello 1001111,

          I agree with Zigfried.

          A sessionIterator would provide you the start and end time of the trading session already automatically converted to your local PC Clock time zone.

          No need to do any work converting the times when using a sessionIterator as it will already provide you the session start time in your local time zone.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            That's correct. But I didn't just want digital trade to be opened up, I also wanted the normal initial balance. I need the other time.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            81 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            42 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            64 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            66 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            54 views
            0 likes
            Last Post CarlTrading  
            Working...
            X