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

Confusing GetNextBeginEnd Results

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

    Confusing GetNextBeginEnd Results

    Code Snippet in OnBarUpdate:


    if ( Bars.FirstBarOfSession)
    {
    Bars.Session.GetNextBeginEnd(Time[0], out sessionBegin, out sessionEnd);
    Print("Time: "+Time[0]);
    Print("sessionBegin: "+sessionBegin);
    PrintTrace("sessionEnd: "+sessionEnd);
    }

    Results for CME US Index Futures RTH Session are exactly as I expect:
    Time: 5/4/2011 9:30:00 AM
    sessionBegin: 5/4/2011 9:30:00 AM
    sessionEnd: 5/4/2011 4:15:00 PM

    Results for Default 24/7 Session seem wrong to me:
    Time: 5/4/2011 12:00:00 AM
    sessionBegin: 5/3/2011 12:00:00 AM
    sessionEnd: 5/4/2011 12:00:00 AM


    I expected to see the following for the Default 24/7 Session:
    Time: 5/4/2011 12:00:00 AM
    sessionBegin: 5/4/2011 12:00:00 AM
    sessionEnd: 5/5/2011 12:00:00 AM

    Is there a simple and clear explanation?
    If the documentation in the HelpGuide is intended to be an explanation of this, I really think some examples might be in order.

    #2
    Hi Miker,

    I can see how you would want to see the date as you list it there, but the output is expected when the session times overlap like that. The bar you're identifying is both the first bar of one session and the last bar of the previous session. You can setup a custom session template without overlapping times and it should work more like you expect.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      So you folks don't consider that a DEFECT ?!
      Am I the first person to point this out?
      What good is GetNextBeginEnd if it's behaviour doesn't make any sense and is not consistent?
      After all, NEXT impies future and "sessionBegin: 5/3/2011 12:00:00 AM" ISN'T!
      Can you think of any way I could anticipate this odd behaviour programmatically? Can I simply assume that if a sessionBegin.Day precedes Time[0].Day that I should add a day to "correct" the sessionBegin error, when Time[0] is on Bars.FirstBarOfSession?

      Comment


        #4
        One more question...why isn't the default 24/7 session template already defined to not be overlapping?

        Comment


          #5
          Thanks for the reply, Miker. We are checking into this currently and will update you later today.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            miker,

            You are not the first to observe this and NT has already introduced a new signature method for GetNextBeginEnd() to address this use case. The new signature will be available in the next version of NT7.

            Here is the deal. The current signature you are using is tied to timestamps only. It does not care about the concept of FirstBarOfSession and runs purely off of the comparison of the input time versus the session template's begin/end times to determine which session the timestamp you pass in belongs into.

            Let us consider your Default 24/7 example. The two sessions in question are as follows:
            5/3 12:00AM to 5/4 12:00AM
            5/4 12:00AM to 5/5 12:00AM
            The time that was passed into the method was 5/4 12:00AM. Since NT timestamps are end-of-bar timestamps what such a 5/4 12:00AM timestamp means is that getting such a timestamp requires the data to have occurred on or before 12:00AM. Since it occurred before, that means it falls into that 5/3 to 5/4 session and that is why you get that particular session begin/end times out of the method.

            Now let us consider your RTH example. The two sessions in question are as follows:
            5/3 9:30AM - 5/3 4:15PM
            5/4 9:30AM - 5/4 4:15PM
            You pass in a timestamp of 5/4 9:30AM. The method again considers this as an end-of-bar timestamp meaning it assumes such a timestamp contains data prior to 9:30AM. But since in this case the session template sees that the session prior to this timestamp already ended at 5/3 4:15PM and that 5/4 9:30AM is clearly after that session the method sees this timestamp as if it were inbetween the two sessions. When you pass in a timestamp inbetween two sessions what happens is it follows the way the name suggests and "gets the next" begin. That one happens to be 5/4 9:30AM and so you get that as the session begin and 5/4 4:15PM as the end.

            Finally, for your question about Default 24/7 overlapping; it is not overlapping.
            5/3 12:00AM - 5/4 12:00AM contains data all the way up to 5/4 12:00:00AM.
            5/4 12:00AM - 5/5 12:00AM contains data starting from anything AFTER 5/4 12:00:00AM
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thanks for that thorough explanation Josh.
              Looking forward to learning more about the new signature method for GetNextBeginEnd().
              I assume I can infer from your comments that the new signature method will be generate the results I was expecting when FirstBarOfSession is true?

              Comment


                #8
                miker,

                Correct, the new signature will be tied to the Bars object and as such will be capable of following along with FirstBarOfSession.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Aviram Y, Today, 05:29 AM
                0 responses
                2 views
                0 likes
                Last Post Aviram Y  
                Started by quantismo, 04-17-2024, 05:13 PM
                3 responses
                27 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by ScottWalsh, 04-16-2024, 04:29 PM
                7 responses
                34 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by cls71, Today, 04:45 AM
                0 responses
                6 views
                0 likes
                Last Post cls71
                by cls71
                 
                Started by mjairg, 07-20-2023, 11:57 PM
                3 responses
                218 views
                1 like
                Last Post PaulMohn  
                Working...
                X