Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars.TradingHours.Sessions[0].Begin/EndTime Documentation

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

    Bars.TradingHours.Sessions[0].Begin/EndTime Documentation

    Was looking at this help file:
    NinjaScript > Language Reference > Common > Data > TradingHours > Sessions

    There's this example provided at the bottom of the page:

    Code:
    protected override void OnBarUpdate()
    {
         // When the current time is within 10 minutes of the first session close, do something (ToTime()'s format is hhmmss)
         if (Bars.TradingHours.Sessions[0].EndTime - ToTime(Time[0]) == 1000)
              // Do something
    }
    This doesn't work as Bars.TradingHours.Sessions[0].BeginTime and EndTime return an integer in a hhmm format (seconds omitted) whereas ToTime returns hhmmss. Thus, the first needs to be multiplied by 100 for the example to be true.

    Thought this might have been just because I was using minute bars, but it seems tick bars also cause Bars.TradingHours.Sessions[0].BeginTime and EndTime to return an int in hhmm format.

    In addition, might be worth it to note in the help file that these both return exchange time rather than local time.

    #2
    I was working with Sessions earlier today and bumped into something related that may help.

    The SessionIterator is only valid for real-time data. So, for historical data, you need to make your own SessionIteator to get these values back in time.

    Code:
     [COLOR=#080808]  SessionIterator[/COLOR] [COLOR=#080808]m_session[/COLOR]=[COLOR=#0000ff]new[/COLOR] [COLOR=#080808]SessionIterator[/COLOR]([COLOR=#080808]Bars[/COLOR]);
     
     [COLOR=#080808]  m_session[/COLOR].[COLOR=#080808]CalculateTradingDay[/COLOR]([COLOR=#080808]Time[/COLOR][[COLOR=#ff8c00]0[/COLOR]],[COLOR=#0000ff]true[/COLOR]);
     
     [COLOR=#080808]  m_StartSession[/COLOR]=[COLOR=#080808]m_session[/COLOR].[COLOR=#080808]ActualSessionBegin;
     [/COLOR]
    There is a caution in the manual about not doing this often as "CalculateTradingDay" is a costly function. I use this on the first bar of session.

    If you access:
    Bars.SessionIterator.ActualSessionBegin;

    You will get the session beginning time for "NOW".

    Comment


      #3
      Thanks for the feedback, we'll have the help guide fixed in near future.
      MatthewNinjaTrader Product Management

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by mintos, 04-02-2024, 08:22 PM
      6 responses
      34 views
      0 likes
      Last Post mintos
      by mintos
       
      Started by claxxical, 05-30-2017, 12:30 PM
      38 responses
      4,480 views
      0 likes
      Last Post alancurry  
      Started by Felix Reichert, 04-26-2024, 02:12 PM
      10 responses
      70 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by PaulMohn, 04-24-2024, 03:49 AM
      4 responses
      37 views
      0 likes
      Last Post PaulMohn  
      Started by lightsun47, Today, 11:37 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Working...
      X