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

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(dateTimeBars.TradingHours.TimeZoneInfoTimeZoneInfo.Local));              
    }
    &
    #8203; 



    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 llanqui, Today, 03:51 PM
            0 responses
            5 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by Quanto, 04-17-2024, 10:43 AM
            2 responses
            23 views
            0 likes
            Last Post Quanto
            by Quanto
             
            Started by Irukandji, Today, 03:06 PM
            0 responses
            7 views
            0 likes
            Last Post Irukandji  
            Started by cmtjoancolmenero, 04-25-2024, 03:58 PM
            17 responses
            96 views
            0 likes
            Last Post cmtjoancolmenero  
            Started by nleitman, Today, 11:46 AM
            8 responses
            20 views
            0 likes
            Last Post nleitman  
            Working...
            X