Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 02-16-2017, 02:09 PM   #1
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,120
Thanks: 175
Thanked 696 times in 538 posts
Default GetNextSession() 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 at 06:19 AM. Reason: False spelling in headline
Harry is offline  
Reply With Quote
Old 02-16-2017, 03:33 PM   #2
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,380
Thanks: 205
Thanked 501 times in 493 posts
Default

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.
NinjaTrader_JessicaP is online now  
Reply With Quote
Old 02-16-2017, 05:08 PM   #3
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,120
Thanks: 175
Thanked 696 times in 538 posts
Default

Quote:
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 at 06:20 AM.
Harry is offline  
Reply With Quote
Old 02-16-2017, 05:26 PM   #4
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,120
Thanks: 175
Thanked 696 times in 538 posts
Default

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.
Harry is offline  
Reply With Quote
Old 02-17-2017, 11:17 AM   #5
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,380
Thanks: 205
Thanked 501 times in 493 posts
Default

I am reviewing the specifications for these two methods and will return shortly.
NinjaTrader_JessicaP is online now  
Reply With Quote
Old 02-17-2017, 12:12 PM   #6
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,120
Thanks: 175
Thanked 696 times in 538 posts
Default

Quote:
Originally Posted by NinjaTrader_JessicaP View Post
I am reviewing the specifications for these two methods and will return shortly.
Thank you!
Harry is offline  
Reply With Quote
Old 02-17-2017, 02:51 PM   #7
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,380
Thanks: 205
Thanked 501 times in 493 posts
Default

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.
NinjaTrader_JessicaP is online now  
Reply With Quote
The following user says thank you to NinjaTrader_JessicaP for this post:
Old 02-17-2017, 04:02 PM   #8
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,120
Thanks: 175
Thanked 696 times in 538 posts
Default

Quote:
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).
Harry is offline  
Reply With Quote
Old 02-20-2017, 07:39 AM   #9
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,380
Thanks: 205
Thanked 501 times in 493 posts
Default

Quote:
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.

Quote:
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
NinjaTrader_JessicaP is online now  
Reply With Quote
The following user says thank you to NinjaTrader_JessicaP for this post:
Old 02-20-2017, 08:27 AM   #10
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,120
Thanks: 175
Thanked 696 times in 538 posts
Default 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.

Quote:
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().

Quote:
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
File Type: zip TestSessionIterator.zip (1.6 KB, 0 views)
Harry is offline  
Reply With Quote
Old 02-20-2017, 08:56 AM   #11
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,380
Thanks: 205
Thanked 501 times in 493 posts
Default

Quote:
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.

Quote:
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.

Quote:
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.
NinjaTrader_JessicaP is online now  
Reply With Quote
Old 02-20-2017, 09:57 AM   #12
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,120
Thanks: 175
Thanked 696 times in 538 posts
Default

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 at 10:27 AM.
Harry is offline  
Reply With Quote
Old 02-20-2017, 09:59 AM   #13
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,380
Thanks: 205
Thanked 501 times in 493 posts
Default

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.
NinjaTrader_JessicaP is online now  
Reply With Quote
The following user says thank you to NinjaTrader_JessicaP for this post:
Old 02-22-2017, 08:50 AM   #14
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,380
Thanks: 205
Thanked 501 times in 493 posts
Default

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.
NinjaTrader_JessicaP is online now  
Reply With Quote
The following user says thank you to NinjaTrader_JessicaP for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 09:42 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.