I have a BarsType that counts the delta and when delta reaches a max value then a new bar is added. E.g. if max value is 500 and the delta reaches -500 or + 500 the bar is updated and a new bar starts. That works fine, without problems.
To monitor the correct behaviour of the bar, I implemented a small indicator that also counts the delta.
In the indicator I added a 1 tick data series and in OnBarUpdate I calculate the delta with every tick until a new bar starts.
To find out if a new bar starts, I use a variable lastBar and remember CurrentBars[0].
My assumption is, that when CurrentBars[0] > lastbar, then a new bar starts and I reset the delta counter.
if ((BarsInProgress == 0) && (CurrentBars[0] > lastBar))
{
}
Now it happens that in the indicator the new bar starts starts to early. The barsType has not yet added the new bar, but the indicator already got the new bar.
In the attached screenshot you can see on the left the debug info from the barsType and on the right the debug from the indicator.
On the left, at the tick with the volume 25 the delta is more then 500 and the new bar is added.
On the right, the bars counter increases before the tick with the 25 volume is processed. The correct tick to increase the CurrentBars counter would be after the tick with 25 volume.
My question is now, how can I identify the correct tick when a new bar was really created?

Comment