Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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.
If you have a template with two sessions added into it, how do you reference specifically one and not the other?
I.e. when you use "Bars.Session.GetNextBeginEnd(Bars, 0, out sessionBegin, out sessionEnd);"...... how does it know which template for each day you are trying to point it to?
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.
So..... since you can't actually reference an individual session template on a chart.......
Do you just create a template that has all the hours you need, i.e. a 24 hour chart, then just start counters at each session change by comparing it to a time?
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.
Yes, that would be the simplest indicator which differeniates between ETH and RTH sessions.
You can have a look at
line 262 -> checks for a new trading day (calls a subroutine which uses GetTradingDayFromLocal())
line 271 -> sessionCount is set to 1 for the first session
line 307 -> sessionCount is increased by 1