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 f.saeidi, Today, 11:02 AM
      1 response
      1 view
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by geotrades1, Today, 10:02 AM
      4 responses
      12 views
      0 likes
      Last Post geotrades1  
      Started by rajendrasubedi2023, Today, 09:50 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by lorem, Today, 09:18 AM
      2 responses
      11 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by geddyisodin, Today, 05:20 AM
      4 responses
      30 views
      0 likes
      Last Post geddyisodin  
      Working...
      X