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 DayTradingDEMON, Today, 09:28 AM
      3 responses
      19 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Stanfillirenfro, Today, 07:23 AM
      9 responses
      23 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by George21, Today, 10:07 AM
      0 responses
      8 views
      0 likes
      Last Post George21  
      Started by navyguy06, Today, 09:28 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      8 responses
      34 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X