Say you where using a ETH session template for ES, as you main look of your chart. And then you decide you want to be able to reference the Open/Close price/time of "CME Index Futures RTH" template. How and when do you reference it?
You can only reference something that is there. That means that if you want to reference the opening time of the RTH session, then you need to use a session template, which actually includes that time.
I use a session template with two sessions per day, as is attached.
To reference the session start time and the session end time of the current session you can use
Now, if you have several sessions per day, you will need to find out whether your current session is the night session or the day session.
There is another NinjaScript method that may help you:
If this value increase by one day, if you detect a FirstBarOfSession event, then it is the start of the night session. If it does not increase, it is the start of the RTH session. You can then collect the session start time and use it for whatever you need to know.
As a coding example you can have a look at the OpeningRange indicator which uses these NinjaScript methods.
The following 2 users say Thank You to Fat Tails for this post:
This can only be done indirectly. I keep track of the current trading day and then count the sessions. First I check, whether the current trading day changed when a Bars.FirstBarOfSession event occurs. If this is the case, then I label this session as session number 1 and store the session start time and session end time. Then I count the sessions until the next trading day starts.
It is not possible to access the session start and end times of the different sessions directly. The only way to do it is to use Bars.Session.GetNextBeginEnd(Bars, 0, out sessionBegin, out sessionEnd) and store those values along with the intradays session count, if you want to retrieve them later.
Attached is my session template for FOREX. It has three distinct sessions per day, so every trading day there are three bars for which Bars.FirstBarOfSession returns the value "true". The enitre trading day covers three sessions. NinjaTrader will decide on its own, which of the three sessions starts the trading day. This is a weakness of the product and needs reengineering. The user should decide upon the first session of the day. The heuristics used by NinjaTrader works in 95% of all cases, but not always. In some cases it is impossible to set up the session template that you want.
I just use a counter. When the trading day starts - detected by GetTradingDayFromLocal() - I set the counter to 1.
When the second session of the trading day starts - detected by Bars.FirstBarOfSession - I set the counter to 2, for the third session of the trading day, I set it to 3. This is not difficult to do and the counter will always tell you which is your current trading session.
So I do not need to compare the time of the bar with the opening time of London or New York. I just us Bars.FirstBarOfSession as a trigger to count the intraday sessions.
You can have a look at the SessionPivots indicators - easiest would be anaCurrentDayOHL - to understand how I use it.