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 yertle, Yesterday, 08:38 AM
      7 responses
      28 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by bmartz, 03-12-2024, 06:12 AM
      2 responses
      21 views
      0 likes
      Last Post bmartz
      by bmartz
       
      Started by funk10101, Today, 12:02 AM
      0 responses
      6 views
      0 likes
      Last Post funk10101  
      Started by gravdigaz6, Yesterday, 11:40 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by MarianApalaghiei, Yesterday, 10:49 PM
      3 responses
      11 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X