Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Confused with GetNextSession()

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

    Confused with GetNextSession()

    Hello. I wanted to code something that stopped my strategy trading on Partial Holidays. After searching previous posts and info I came up with the following:

    Code:
                 private DateTime PartialHolidayBlock
                 if (Bars.IsFirstBarOfSession)        
                 {        
                    // GET NEXT SESSION
                    sessionIterator.GetNextSession(Time[0], true);
                    // 
                    sessionIterator.GetNextSession(sessionIterator.ActualSessionEnd.AddMinutes(1), true);
    
                    
                    // DICTIONARY CHECK FOR PARTIAL HOLIDAY
                    if (TradingHours.PartialHolidays.ContainsKey(sessionIterator.ActualSessionBegin))
                    {
                           Print("The Next Session is a Partial Holiday: " + sessionIterator.ActualSessionBegin);
                        PartialHolidayBlock = sessionIterator.ActualSessionBegin;    
                    }
                    
                    // Block Everything if Today's Trading Date is equal to a Partial Holiday    
                    if (PartialHolidayBlock == sessionIterator.GetTradingDay(Time[0]))
                    {
                        Print("DO NOT TRADE TODAY: " + PartialHolidayBlock);
                    }
                    else
                    {
                        Print("NORMAL TRADING DAY = " + sessionIterator.GetTradingDay(Time[0]));
                    }
                 }​
    It works perfectly. However, I'm finding the use of GetNextSession quite confusing. This was post where I got the line that adds 1 minute to the EndSession time in order to get the start of the next session and it's the only part of the code I don't understand;

    Code:
     sessionIterator.GetNextSession(sessionIterator.ActualSessionEnd.AddMinutes(1), true);


    Can someone explain this a bit further. If the session ends at 17:00, how does making it 17:01 enable us to get the DateTime of the next session?


    #2
    Hello several,

    The name of GetNextSession() can be a bit confusing.

    This is getting the next session based on the datetime provided. If the time provided is during a session, the current session is the next session for the current time.

    It may make more sense to think of this as get current session, except if the date time provided is out of session it returns the upcoming session and not the session that most recently ended.

    If the current session is the next session relative to the datetime provided, calling GetNextSession() to get the current session then using the end time of the session and adding 1 minute will move datetime past the end of the session. Calling GetNextSession() again with this datetime that is 1 minute past the end of the current session will load the next session relative to the datetime.

    This means it gets the session info of the next available session in relation to 1 minute after the current session.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks. I understand.

      Just a note also incase anyone follows later. I realized the code I posted above didn't fully work. Once I write the line:

      sessionIterator.GetNextSession(sessionIterator.Act ualSessionEnd.AddMinutes(1), true);

      Then everything that comes after is relative to that.ie, sessionIterator.ActualSessionBegin sessionIterator.GetTradingDay etc....

      Once I stored PartialHolidayBlock = sessionIterator.ActualSessionBegin; I would then have to reset with sessionIterator.GetNextSession(Time[0], true); to get the current days values again

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      111 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      59 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      38 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      42 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      78 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X