You need to print the bar's timestamp to see which bar is being processed. There is little value in theorizing what should/should not happen. Please figure out which is the bar being processed and then we can see how that relates to the first session bar.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy behavior
Collapse
X
-
sublime,
You need to print the bar's timestamp to see which bar is being processed. There is little value in theorizing what should/should not happen. Please figure out which is the bar being processed and then we can see how that relates to the first session bar.Josh P.NinjaTrader Customer Service
-
Ok, I'll do it tomorrow during a live session again, but we already know the result, right? At the session start, we have two possible bars that it can process - the current bar or the previous bar. If it executes an order 4 seconds into the session, I think we can be assured its not the current 5 min bar.Originally posted by NinjaTrader_Josh View Postsublime,
You need to print the bar's timestamp to see which bar is being processed. There is little value in theorizing what should/should not happen. Please figure out which is the bar being processed and then we can see how that relates to the first session bar.
As I said at the beginning of the day, its a simple question that can now be summarized :
Why would a 5 min strategy execute an order 4 seconds after the session start?
Comment
-
Nope. When you have if (Historical) it is impossible for you to be processing any historical bars. You will only process real-time bars. Depending on what you have for your session times a 2:15PM session start time means process that 2:15 bar. A bar of 2:15 contains the information from 2:10-2:15. It closes at 2:15 and is completely capable of having an order accepted at 2:15:04 since that is past the closing time of the bar when it was processed.Josh P.NinjaTrader Customer Service
Comment
-
Well, that's it. I think you solved it, but that is really misleading. So, in the 5 min strategy, I can simply set the Session Begins parameter to 8:35am. This means the first bar that will process is the 8:35 bar which contains data from 8:30 to 8:35. This is exactly what is desired.Originally posted by NinjaTrader_Josh View PostNope. When you have if (Historical) it is impossible for you to be processing any historical bars. You will only process real-time bars. Depending on what you have for your session times a 2:15PM session start time means process that 2:15 bar. A bar of 2:15 contains the information from 2:10-2:15. It closes at 2:15 and is completely capable of having an order accepted at 2:15:04 since that is past the closing time of the bar when it was processed.
But you can see the confusion. For instance, pull up a 5 min chart of anything. The first bar has a time stamp of 8:35 am. Select the chart properties and look at the Session Begin parameter. It will read 8:30 am, not 8:35am. Which makes sense to me... the session begins at 8:30 and the first bar will be from 8:30 to 8:35. The chart won't show me the 8:25-30 bar.
This logic is also consistent in backtesting. If you choose a Session Begins of 8:30 am and run our same 5 min bar strategy, you will never see an order execution on the 8:30-8:35 bar (first bar). Every execution will be on the 8:40 bar or after. Why? Because with CalculateOnBarClose set to true, it waits until the 8:30-35 bar closes before evaluating OnBarUpdate(). This is all I want to achieve in realtime...simple right?
So in migrating to live trading, of course, I set the Sessions Begins parameter to 8:30 am. That's the time to use both on the chart and in backtesting. But unlike backtesting or a chart, you are informing me, and my experience suggests, the first bar will then be the 8:25-30 bar.
If this is, in fact, true, can you appreciate the confusion? The Session Begins parameter makes perfect sense on the chart and backtesting, but then means something different in a realtime environment. In my mind, when I set a session begins at 8:30am, to me, and I would think most, it would mean, start realtime trading at 8:30 am and move forward in 5 min increments to evaluate program logic. In this case, the 8:25-30 bar is historical, not realtime.
I will try it out tomorrow... but in the future can we change the title of that field to "beginning bar timestamp"? or better yet, change the logic behind the field to work like it does in the chart and backtesting modules?
Comment
-
sublime,
When you say 8:30 for your session start, the bar being built is the 8:35 bar. What is happening is any order from your prior session's last bar is being placed the moment the 8:30-8:35 bar begins building. That is why you see the order at ~8:30.
You should run with if (Historical) return; AND set your session begin times. Then it should work the way you desire.Josh P.NinjaTrader Customer Service
Comment
-
Agreed, the solution is as follows:Originally posted by NinjaTrader_Josh View Postsublime,
When you say 8:30 for your session start, the bar being built is the 8:35 bar. What is happening is any order from your prior session's last bar is being placed the moment the 8:30-8:35 bar begins building. That is why you see the order at ~8:30.
You should run with if (Historical) return; AND set your session begin times. Then it should work the way you desire.
In a realtime strategy, the "session begins" parameter should be set to the timestamp of the first bar to avoid the execution of a trade from the prior session's last bar.
So a strategy that desires to begin trading from the information included in the 8:30-35 bar needs to set the "Session Begins" parameter to 8:35 AM, not 8:30 AM.
Basically, at the beginning of any realtime session, the strategy closes the prior bar, which fires the OnBarUpdate(). If this results in a trade, it means you are executing a trade in the current live session based on information from the prior session. And in many cases... this information is around 18 hours old. I think I can state fairly unequivocally that this behavior is universally undesirable.
However, the solution is simple, I just wish I would have known about it. My instincts tell me that NT is designed in such a way that it has to close a bar before it can start a new one. I have no problem with that, I just don't think its inherently intuitive to a strategy developer. As I said, I'm pleased to have a solution, and may I suggest that this information might be of value to the rest of the NT community. I know it will help me more closely match my backtesting results. And really, it was my last hurdle to going live.
Thanks again Josh in helping to understand and arrive at a solution.
P.S. What added to the confusion is that many times the close of the previous bar and subsequent OnBarUpdate() would not result in a trade at the session open. Which led me to believe that the strategy was working as desired. Then, other days it would execute an opening trade. This apparent inconsistent behavior decreased confidence and led to dubious results. My confidence is restored.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
639 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
366 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
569 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
572 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment