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

Bars.GetTradingDayFromLocal with time?

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

    Bars.GetTradingDayFromLocal with time?

    Is there a function like Bars.GetTradingDayFromLocal that will also return the local time as well and not just the date?

    I currently use TimeZoneInfo.ConvertTime but have to hard code FindSystemTimeZoneById for each instrument. Or is there a way to get the FindSystemTimeZoneById for a session id or instrument?

    For example I currently use the following on the HangSeng:
    DateTime ExchangeDateTime = TimeZoneInfo.ConvertTime(Times[BarsInProgress][0], TimeZoneInfo.FindSystemTimeZoneById("China Standard Time"));

    What I do now works fine I just didn't know if there was an better way.

    #2
    Hello ct,

    Thanks for your post.

    I want to clarify what you are wanting to do.

    Currently what is your time zone?

    To confirm, you are attempting to convert a bar time to the 'China Standard Time' time zone and this is not your current time zone, is this correct?

    Real-time and historical data are already automatically converted to your local time zone as they are received. Are you trying to convert the start time of a session from a different time zone to your time zone?

    Are you trying to find the start time and date of session for a bar by providing the time of that bar?
    This would be what GetNextBeginEnd is for.
    Bars.Session.GetNextBeginEnd(Time[0], out sessionBegin, out sessionEnd);
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ChelseaB

      I am in New Zealand but keep my computer on New York time to make it easier for my mind to keep in sync with news and other things. Not much is reported in New Zealand time which is a day ahead of everything.

      A lot of my code tracks both ETH and RTH info. Rather than create unique session templates I just split the session using my code. I want to know the actual date/time in Hong Kong when looking at an HSI or MHI chart and my computer is on New York time.

      I do all this now but have the target time zone name (eg, "China Standard Time") hard coded. It is in the session template but I can't find a way to access it so I can reference it. Normally this is not an issue but HSI and MHI session cross a USA day. Part of the session is one in USA day and the second half is in another USA day. It's a pain but I can handle it. What I have works but I have this programming issue about hard coding, avoid it if you can.

      I hope that sheds a little light on the subject.

      Comment


        #4
        Hi ct,

        Are you wanting to convert to the time zone of the session of the bars on the chart?

        Print(TimeZoneInfo.ConvertTimeBySystemTimeZoneId(T ime[0], Bars.Session.TimeZoneInfo.Id));
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ChelseaB

          Bullseye. This is a snippet of the code I use today.

          DateTime ExchangeDateTime = TimeZoneInfo.ConvertTime(Times[BarsInProgress][0], TimeZoneInfo.FindSystemTimeZoneById("China Standard Time"));
          if (ExchangeDateTime.Hour == 9 && ExchangeDateTime.Minute >= 15
          || ExchangeDateTime.Hour == 16 && ExchangeDateTime.Minute <= 15
          || ExchangeDateTime.Hour >= 10 && ExchangeDateTime.Hour < 16)
          {
          RTHActive = true;
          }

          I think that is exactly what I wanted. Just tested and confirmed it.

          ChelseaB, You get a gold star!!!!
          Last edited by ct; 10-26-2015, 08:15 PM.

          Comment


            #6
            ChelseaB

            Trying to convert my nt7 to nt8.

            on NT7 i had"DateTime ExchangeDateTime = TimeZoneInfo.ConvertTime(Times[BarsInProgress][0], TimeZoneInfo.FindSystemTimeZoneById(Bars.Session.T imeZoneInfo.Id));
            DateTime ExchangeDateTime = TimeZoneInfo.ConvertTime(Times[BarsInProgress][0], TimeZoneInfo.FindSystemTimeZoneById(Bars.TradingHo urs.TimeZoneInfo));"


            On nt8 tried using: " TimeZoneInfo.FindSystemTimeZoneById(Bars.TradingHo urs.TimeZoneInfo));"
            but compiler was not happy.
            What would be the correct nt8 syntax to convert "Time[0]" to exchange time?

            Comment


              #7
              Hi ct,

              To clarify, you want to get the time zone information from the TradingHours template and then convert the time to the timezone of that template, is this correct?

              I'm trying to clarify what your time zone is and what you are trying to convert the time from.

              Is the "China Standard Time" the timezone of the TradingHours template and you are trying to convert your local time to that time zone?

              If so, the TradeHours object itself will have that timezone info object you can use directly.

              http://ninjatrader.com/support/helpG...mezoneinfo.htm
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Sparkyboy, Today, 10:57 AM
              0 responses
              0 views
              0 likes
              Last Post Sparkyboy  
              Started by TheMarlin801, 10-13-2020, 01:40 AM
              21 responses
              3,916 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by timmbbo, 07-05-2023, 10:21 PM
              3 responses
              152 views
              0 likes
              Last Post grayfrog  
              Started by Lumbeezl, 01-11-2022, 06:50 PM
              30 responses
              808 views
              1 like
              Last Post grayfrog  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Erick  
              Working...
              X