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

Get next session's start time, handling partial holidays & cross-time zone issues?

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

    Get next session's start time, handling partial holidays & cross-time zone issues?

    Hello,

    How can one get NinjaTrader 8's best guess for the next session's start date and time (not the current session's start date and time, i.e. the session containing Time[0]), including handling of partial and full planned holidays, and in a way that can handle cross-time zone issues?

    I was hoping that SessionIterator.GetNextSession() would get an object containing the start date and time of the session that is predicted to occur directly after the current session if Time[0] was passed to it, but unfortunately it gets an object containing the start date and time of the current session, i.e. the session that contains the price bar with the time returned by Time[0].

    Simply adding 1 day to Time[0] of a 1-day daily bar and calling SessionIterator.GetNextSession() with the new datetime also won't work because not only could the next day be a weekend or full holiday, but SessionIterator.GetNextSession() does not get an object containing the start date and time of a session if the datetime passed to it is outside of the session, and sometimes due to partial holidays or daylight savings time, adding 1 day or 24 hours to the end time of the current session's end time (Time[0] of the current 1-day daily bar) can return a time that is after the closing time of the next session and therefore not a time that should be passed to SessionIterator.GetNextSession() if an object containing the next session's start date and time is desired.

    Thanks in advance!

    EquityTrader

    #2
    Hello EquityTrader,

    You are correct that GetNextSession() actually gets the current session of the date time supplied and not the next session.

    Unfortunately, you would need to add a minute to the current session close time to get the next session.

    This will account for holidays and weekends.

    Code:
    sessionIterator.GetNextSession(Time[0], true);
    sessionIterator.GetNextSession(sessionIterator.ActualSessionEnd.AddMinutes(1), true);
    Print(string.Format("Current bar: {0} | Get next session +1 minute actual begin bar: {1}", Time[0], sessionIterator.ActualSessionBegin));
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thank you very much for the helpful and informative response. I will give it a try.

      EquityTrader

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by alexstox, 10-16-2018, 03:29 PM
      11 responses
      342 views
      0 likes
      Last Post aligator  
      Started by ageeholdings, 05-01-2024, 05:22 AM
      6 responses
      42 views
      0 likes
      Last Post ageeholdings  
      Started by tony_28217, Today, 07:04 PM
      0 responses
      11 views
      0 likes
      Last Post tony_28217  
      Started by flybuzz, Today, 10:33 AM
      1 response
      9 views
      0 likes
      Last Post flybuzz
      by flybuzz
       
      Started by spencerp92, 10-10-2023, 09:56 AM
      4 responses
      309 views
      0 likes
      Last Post flybuzz
      by flybuzz
       
      Working...
      X