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)
If you really want to include all the bars of current session, and not just the current bar, then you would need to do some logic check for the current bar date vs the Bars.Session stuff. I don't have Ninja up and haven't looked at that kind of code in years, but you can find sessions under Bars.Session* if I remember right.
Otherwise the if (Historical) return; would get you 99% there.
Before I answer, I need to come back to a definition
Trading day: Refers to the contract of the instrument that you trade. For example for ES the trading day currently starts at 3:30 PM Central Time and ends at 3:15 PM Central Time next day. Starting from November 18, the trading day for ES will start at 5:00 PM Central Time and end at 4:15 PM Central Time.
Session: Part of the trading day. For ES there could be night session from 3:30 PM to 8:30 AM and a day session from 8:30 AM to 3:15 PM.
NinjaTrader uses both the concept of the trading day and the session. A trading day can be made up of 1, 2 or 3 sessions - theoretically there could be more than 3, but I have never seen any practical application.
I assume that you want to know how to avoid to process any bars prior to the current trading day. I do not know why you want to do that, there is really no need, as you can easily code indicators that reset at the beginning of each session. For example, I have coded a SMA that resets at the start of the session to apply it to the NYSE Tick, because I do not want to include tick values of the prior trading day.
But coming back to your question, this is how not to process bars of the prior trading day:
(1) collect the current time
(2) find the start time (date, hour, minutes) of the trading day
(3) check each bar that is processed, whether it has a time stamp prior to the start of the trading day or afterwards
Current Time
You may use DateTime.Now. If you are connected to Market Replay you can use a method Now
Find the start of the current session
will retrieve the session begin and end time of the current session of the primary bars. I have used the method Now defined above.
Check whether the current bar processed belongs to the current session
If you want to check whether the timestamp of the current bar belongs to the session that includes "Now", you have to differentiate between 2 cases.
Bars Built from ticks: You need to check, whether the timestamp iof the processed bar iss greater or equal that the value for sessionBegin.
Minute bars: You need to check, whether the timestamp of the processed bar is greater than the value for sessionBegin.
For example, if your ES session starts at 8:30 AM Central Time, then
-> a minute bar with the timestamp of 8:30 belongs to the prior session, you do not want to include it
-> a tick built bar (tick, volume, range, Renko bars ....) with the timestamp of 8:30 belongs to the current session, you want to include it
Attention
Depending on how you implement that concept, it will reset your indicators at the session start or it will not. I personally cannot imagine any reason to eliminate the bars of the prior session. Your request looks strange to me, and you have not explained what it can be used for.
The reason I want to process just the current session's bars is that as I'm processing 1 tick series and my
processing incurs an overhead which involves communication to external program - I need to make sure
the overhead when loading a chart which has long history is minimal.
The reason I want to process just the current session's bars is that as I'm processing 1 tick series and my
processing incurs an overhead which involves communication to external program - I need to make sure
the overhead when loading a chart which has long history is minimal.
What about opening a chart with a lookback period of 1 or 2 days?
If you leave out the data prior to the current trading day, your indicators may display false values. Each indicator has a training period, for recursive indicators this can be pretty long.
What about opening a chart with a lookback period of 1 or 2 days?
If you leave out the data prior to the current trading day, your indicators may display false values. Each indicator has a training period, for recursive indicators this can be pretty long.
No worries - this indicator has no display, it is used just as an integration vehicle to external application which gets tick data from the the NT feed.
If I'm to use the lookback period option, can it be set (by the indicator) ?
Can it be set for each dataseries to be a different value (this is a multi instrument, multi time frame indicator) ?
No worries - this indicator has no display, it is used just as an integration vehicle to external application which gets tick data from the the NT feed.
If I'm to use the lookback period option, can it be set (by the indicator) ?
Can it be set for each dataseries to be a different value (this is a multi instrument, multi time frame indicator) ?
You cannot set the lookback of the chart from the inidcator, and it is not possible to have different values for different instruments.
What you can do is simply check for a start date /start time when OnBarUpdate() is running. For example, if you trade ES and today's session started at 4:30 Eastern Time yesterday, you simply add three lines in the beginning of OnBarUpdate():
You cannot set the lookback of the chart from the inidcator, and it is not possible to have different values for different instruments.
What you can do is simply check for a start date /start time when OnBarUpdate() is running. For example, if you trade ES and today's session started at 4:30 Eastern Time yesterday, you simply add three lines in the beginning of OnBarUpdate():