Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
CurrentBars disparity when using multiple data series
Collapse
X
-
CurrentBars disparity when using multiple data series
When I have 2 data series in a strategy with the same time frame of bars (ES 5-minute bars and NQ 5-minute bars in this example), I get a strange result where the CurrentBars of each data series differ, sometimes by 1 bar and sometimes by 2 bars. I've illustrated this in the attachment which shows the output of a simple script that prints the data series name and that data series CurrentBars number on each OnBarUpdate. You can see that in the beginning, these 2 data series differ by 2 bars, then 1 bar, then occasionally 2 bars again (i have read that the currentbars number will start at -1 until all data series have processed, but this wouldnt explain the discrepancy of 2 bars anyway, so must be something else at play here). Each data series should increment by 1 bar on each bar update, however the 2nd data series seems to sometimes not increment at all, and at other times increment by 2. Is there a way to correct this behavior? A way to sync the data series to reliably increment and perhaps have the same CurrentBars number? Thanks in advance...Tags: None
-
Hello pkr75,
That is correct behavior because you are using two different instruments. They are not synced in who trades each instrument so they will have varied times when data comes in to close bars. You would only be able to sync the same instrument on different timeframes, in that case there is an order to which OnBarUpdate is called. For separate instruments you may see that one trades more than the other so there is no reason they should be in sync.
-
Thank you for your reply Jesse, but I am still a bit confused. Both instruments are 5 minute bars, so each instrument's bar should close every 5 minutes, right? Since I am not dealing in ticks, why should it matter if one instrument trades more than the other? Why would each instruments CurrentBars count not incrementally update every five minutes in this case?
Comment
-
You said "that depends when each instrument gets data to close the bar". What does that mean exactly? If a given instrument is synced to the time, then a 1-minute bar, for example, would close when one minute ends and the next one begins when the clock reads XX:00. But it seems like you are saying that it does not solely depend on time, because you say that an instrument needs to get some type of data in order to close the bar. Can you please explain this to me? What data is needed to close the bar? Thanks for your patience.
Comment
-
Jesse, I actually just found a reply of yours to a 2014 post which was super helpful ( https://ninjatrader.com/support/foru...cundary-series ). I'll use IsFirstTickOfBar in conjunction with BarsInProgress to do my checks before proceeding in the script. Thanks so much!
Comment
-
If I'm wrong on this, I apologise. If I recall correctly, Its been a few years, that if a time bar that does not have any trades during the life of the bar, ie 5-minutes, the bar does not print on the chart and a new bar's timer starts. If this happens on one instrument and not the other, a bar count discrepancy occurs.between the two instruments.Originally posted by pkr75 View PostWhen I have 2 data series in a strategy with the same time frame of bars (ES 5-minute bars and NQ 5-minute bars in this example), I get a strange result where the CurrentBars of each data series differ, sometimes by 1 bar and sometimes by 2 bars. I've illustrated this in the attachment which shows the output of a simple script that prints the data series name and that data series CurrentBars number on each OnBarUpdate. You can see that in the beginning, these 2 data series differ by 2 bars, then 1 bar, then occasionally 2 bars again (i have read that the currentbars number will start at -1 until all data series have processed, but this wouldnt explain the discrepancy of 2 bars anyway, so must be something else at play here). Each data series should increment by 1 bar on each bar update, however the 2nd data series seems to sometimes not increment at all, and at other times increment by 2. Is there a way to correct this behavior? A way to sync the data series to reliably increment and perhaps have the same CurrentBars number? Thanks in advance...
Comment
-
That makes sense RJay, and thanks for your response. In my particular case, it turned out that the discrepancies occured when my script performed an action immediately after one data series had received its first tick but the other data series had not. Therefore the data series which had received its first tick closed the previous bar and updated its CurrentBars number, while the data series which had not received its first tick had not yet closed the previous bar and consequently not yet moved forward to the next CurrentBars number.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
633 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment