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

GetNextSesison() vs. CalculateTradingDay()

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

    GetNextSesison() vs. CalculateTradingDay()

    When I want to access some of the properties of a session iterator such as

    - ActualSessionBegin
    - ActualSessionEnd
    - ActualTradingDayEndLocal
    - ActualTradingDayExchange

    I would first have to call sessionIterator.GetNextSession() or sessionIterator.CalculateTradingDay().

    (1) What is the difference between the two methods?

    (2) Which method is less expensive (takes less resources)?

    The sessionIterator methods allow for accessing the date of the trading day (ActualTradingDayExchange), the closing time of the current trading day expressed in local time (ActualTradingDayEndLocal) , the start and end time of the current session expressed in local time (AcutalSessionBegin, ActualSessionEnd).

    (3) But how would I get the start time of the current trading day?
    Last edited by Harry; 02-20-2017, 06:19 AM. Reason: False spelling in headline

    #2
    Hello Harry, and thank you for your questions.

    To your first and second question, CalculateTradingDay and GetNextSession set up your SessionIterator to point at the same or next trading day, respectively, based on either the passed in date or the current state of the SessionIterator. CalculateTradingDay stays in place, GetNextSession advances. Both are as efficient as each other. The difference is only in the session that SessionIterator ends up pointing at.

    To your third question, you can use CalculateTradingDay, and then ActualSessionBegin, to get the start time of the current trading day.

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JessicaP View Post
      Hello Harry, and thank you for your questions.

      To your first and second question, CalculateTradingDay and GetNextSession set up your SessionIterator to point at the same or next trading day, respectively, based on either the passed in date or the current state of the SessionIterator. CalculateTradingDay stays in place, GetNextSession advances. Both are as efficient as each other. The difference is only in the session that SessionIterator ends up pointing at.

      To your third question, you can use CalculateTradingDay, and then ActualSessionBegin, to get the start time of the current trading day.

      Please let us know if there are any other ways we can help.

      Thank you for your answer. As far as I understand, there is a difference between a session and a trading day. A trading day can be subdivided into several sessions. I have set up various trading hours templates with several intraday sessions.

      It was my understanding that ActualSessionBegin points to the start of the current session and not to the start of the current trading day. Could you please confirm

      -> whether ActualSessionBegin() and ActualSessionEnd() refer to the start and end of a
      trading session
      -> or whether ActualSessionBegin() and ActualSessionEnd() refer to the start and end of a
      trading day
      Last edited by Harry; 02-20-2017, 06:20 AM.

      Comment


        #4
        I have now run a test between CalculateTradingDay() and GetNextSession().

        There seems to be absolutely no difference. This is the code that I have used:

        Code:
        sessionIterator0.CalculateTradingDay(Times[0][0],true);
        Print(sessionIterator0.ActualSessionBegin + "   " + sessionIterator0.ActualSessionEnd);
        sessionIterator0.GetNextSession(Times[0][0],true);
        Print(sessionIterator0.ActualSessionBegin + "   " + sessionIterator0.ActualSessionEnd);
        In both cases I get identical values for ActualSessionBegin() and ActualSessionEnd().

        Furthermore it was easy to find out that ActualSessionBegin() and ActualSessionend() will NOT return start and end time of the trading day, but they will return start and end time of the current session.

        Therefore I am repeating two questions.

        (1) What is the difference between ActualSessionEnd() and GetNextSession()? Both methods do not return anything but need to be executed before the session values can be accessed.

        (3) How would I get the start time of the current trading day? My test has shown that ActualSessionBegin() has not been misnamed, but that it returns the start time of the current session and not the start time of the current trading day.

        Comment


          #5
          I am reviewing the specifications for these two methods and will return shortly.
          Jessica P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_JessicaP View Post
            I am reviewing the specifications for these two methods and will return shortly.
            Thank you!

            Comment


              #7
              Hello Harry,

              I have investigated these two functions. CalculateTradingDay and GetNextSession are nearly equivalent. The only difference between these two methods, is that for CalculateTradingDay, ActualTradingDay will always refer to the Last trading day, unless a time beyond the last trading day is explicitly passed in.

              Please let us know if there are any other ways we can help.
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_JessicaP View Post
                Hello Harry,

                I have investigated these two functions. CalculateTradingDay and GetNextSession are nearly equivalent. The only difference between these two methods, is that for CalculateTradingDay, ActualTradingDay will always refer to the Last trading day, unless a time beyond the last trading day is explicitly passed in.

                Please let us know if there are any other ways we can help.
                Hello Jessica,

                There is no overload for CalculateTradingDay that does not require that a time is passed in. For both CalculateTradingDay() and GetNextSession() you would pass a time to let the session iterator point to a specific session. Then catch the actual trading day to which the session iterator points.

                I do not yet understand the difference from your answer.

                Also you did not yet answer my question, how I can know the start time of a trading day (my third question).

                Comment


                  #9
                  Originally posted by Harry View Post
                  Hello Jessica,

                  There is no overload for CalculateTradingDay that does not require that a time is passed in. For both CalculateTradingDay() and GetNextSession() you would pass a time to let the session iterator point to a specific session. Then catch the actual trading day to which the session iterator points.

                  I do not yet understand the difference from your answer.
                  I will be happy to clarify. If we assume that the last trading day was Wednesday and you passed in a DateTime object from Thursday, GetNextSession will cause the session iterator's ActualTradingDayStart and ActualTradingDayEnd to point at Thursday, and CalculateTradingDay will cause it to point at Wednesday.

                  Also you did not yet answer my question, how I can know the start time of a trading day (my third question).
                  You may use sessionIterator.ActualTradingDayStart and sessionIterator.ActualTradingDayEnd
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    GetNextSession() not pointing to next session

                    Hi Jessica,

                    Thank you for your answers. However, I am not yet satisfied as I fully disagree with all of them. Let me come to the details. Also I do not want to annoy you, but I am genuinely interested in the correct answers.

                    Originally posted by NinjaTrader_JessicaP View Post
                    I will be happy to clarify. If we assume that the last trading day was Wednesday and you passed in a DateTime object from Thursday, GetNextSession will cause the session iterator's ActualTradingDayStart and ActualTradingDayEnd to point at Thursday, and CalculateTradingDay will cause it to point at Wednesday.
                    A quick test - see test indicator attached - shows that CalculateTradingDay() and GetNextSession() point to the same trading day.

                    Even when I use the indicator with a tripartite session template (3 subsessions per trading day) both CalculateTradingDay() and GetNextSession() point to the same subsession.

                    I can not find any difference between CalculateTradingDay() and GetNextSession().

                    Originally posted by NinjaTrader_JessicaP View Post
                    You may usesessionIterator.ActualTradingDayStart and sessionIterator.ActualTradingDayEnd

                    Unfortunately ActualTradingDayStart has never been implented. I would appreciate, if you could pass the message to implement it. I would rather call it ActualTradingDayBeginLocal or ActualTradingDayStartLocal in order to match ActualTradingDayEndLocal (ActualTradingDayEnd does not exist either).

                    Attachement: Quick and dirty indicator that prints ActualSessionBegin, ActualSessionEnd, ActualTradingDayEndLocal from both CalculateTradingDay() and GetNextSessionEnd() to the output file.
                    Attached Files

                    Comment


                      #11
                      Originally posted by Harry View Post
                      Hi Jessica,

                      Thank you for your answers. However, I am not yet satisfied as I fully disagree with all of them. Let me come to the details. Also I do not want to annoy you, but I am genuinely interested in the correct answers.
                      I understand your desire for correct answers and am glad for the opportunity to clarify part of our code base for yourself and other developers. We are always happy to provide this kind of help. If you would prefer this be brought directly to a developer's attention please let us know.

                      A quick test - see test indicator attached - shows that CalculateTradingDay() and GetNextSession() point to the same trading day.

                      Even when I use the indicator with a tripartite session template (3 subsessions per trading day) both CalculateTradingDay() and GetNextSession() point to the same subsession.

                      I can not find any difference between CalculateTradingDay() and GetNextSession().
                      My answer was based on a conversation with one of the developers. CalculateTradingDay calls GetNextSession, which is why these two methods are so similar. Since there are other limits as far as the time you pass in and how it is treated, it will be difficult to construct a scenario where these point at different days, however I have an assurance that the additional check on CalculateTradingDay is of the nature I described.

                      Unfortunately ActualTradingDayStart has never been implented. I would appreciate, if you could pass the message to implement it. I would rather call it ActualTradingDayBeginLocal or ActualTradingDayStartLocal in order to match ActualTradingDayEndLocal (ActualTradingDayEnd does not exist either).

                      Attachement: Quick and dirty indicator that prints ActualSessionBegin, ActualSessionEnd, ActualTradingDayEndLocal from both CalculateTradingDay() and GetNextSessionEnd() to the output file.
                      I would first like to address a mistake on my part. The two variables that can be (but in most cases are not) different between CalculateTradingDay and GetNextSessionEnd are

                      • ActualTradingDayExchange
                      • ActualTradingDayEndLocal

                      This said I have submitted a feature request to the product management team for the following feature :

                      This user would like an ActualTradingDayStartLocal variable to correspond with the ActualTradingDayEndLocal variable for sessionIterators


                      http://ninjatrader.com/support/helpG...oniterator.htm

                      I will follow up with more information as soon as it's available. If the feature requests already exists, a vote will be added to it.

                      Please let us know if there are any other ways we can help.
                      Jessica P.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello Jessica,

                        As your answers were not satisfactory ... I have further investigated.

                        Difference between CalculateFromTradingDay() and GetNextSession().

                        From the language reference I find that GetNextSession() returns a bool which is true in case that GetNextSession() has successfully calculated a session, false otherwise. CalculateTradingDay() returns nothing.

                        Looking closer at GetNextSession() I found:

                        -> that GetNextSession() never points to the next session, but always to the current session
                        -> that GetNextSession() works correctly when a time value is passed to it that lies inside a session
                        -> that the session iterator returns nonsense, when a value is passed to GetNextSession() that is outside a trading session - in this case GetNextSession() will return the value false

                        This has a few implications. When GetNextSession() is used, it is not possible to calculate the begin or end time wiithout checking the value of GetNextSession() first. Therefore I come to the following conclusions:

                        Conclusions

                        (1) CalculateTradingDay() should be used with care, because it remains unclear whether it has successfully calculated a trading day or trading session. Sometimes it performs successfully, sometimes it returns just nonsense. Therefore it cannot be use in all cases.

                        (2) GetNextSession() tells you whether its attempt to calculate a session was successful or not. In case it was successful the values can be used, otherwise they need to be disgarded.

                        (3) GetNextSession() always points to the current trading day and current trading session (remember that a trading day can be composed of several sessions)

                        (4) The help guide / language reference does not explain how to make proprer use of GetNextSession(). The note on top reads

                        This method needs to be used before you can accurately determine various session properties such as ActualSessionBegin or ActualTradingDayEndLocal, etc.

                        This is not the whole truth. In fact you need to

                        - first call GetNextSession()
                        - then check whether it returns a value of true
                        - and only apply other methods such as ActualSessionBegin etc. when GetNextSession() has returned the value true

                        The correct syntax for using GetNextSession() would be

                        Code:
                        if (sessionIterator.GetNextSession(DateTime timeLocal, bool includesEndTimeStamp)
                        {
                              sessionIterator.ActualSessionBegin ....
                              ....
                        }
                        else
                        {
                             // do something different, for example loop forward until GetNextSession() returns the value true
                        }
                        The Help Guide should clearly state

                        - that GetNextSession() points to the current session and not the next one
                        - that the sessionIterator holds nonsense time, when GetNextSession() has returned the value false
                        - that therefore the value returned by GetNextSession() needs to be checked before trying to determine any session begin, session end or end of trading day
                        - that CalculateTradingDay() should not be used for other purposes than determining the current session for a bar timestamp (a bar timestamp is always in session)

                        Please pass the message to include this information with the help file. I have only asked all these questions because they were not available with the language reference.
                        Last edited by Harry; 02-20-2017, 10:27 AM.

                        Comment


                          #13
                          Thank you for this additional information Harry. As I have requested a feature, the product management team is already reviewing this ticket, and any information you add, including suggested changes to the help guide, will automatically be made available to them.
                          Jessica P.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello Harry,

                            This feature is being reviewed by the product management team and has been assigned the following unique tracking ID


                            SFT-1949


                            Please let us know if there is any other way we can help.
                            Jessica P.NinjaTrader Customer Service

                            Comment


                              #15
                              ugh the help guide explanation of this sucks. Thanks Harry for your extra work and added notations. I am experimenting with sessions and will add what i find.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by swestendorf, Today, 11:14 AM
                              2 responses
                              5 views
                              0 likes
                              Last Post NinjaTrader_Kimberly  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              5 responses
                              13 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Mupulen, Today, 11:26 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Mupulen
                              by Mupulen
                               
                              Started by Sparkyboy, Today, 10:57 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by TheMarlin801, 10-13-2020, 01:40 AM
                              21 responses
                              3,917 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Working...
                              X