This might seem like an odd question, but here goes. I use IsFirstTickOfBar, basically, to detect the formation of a new bar and reset various variables to zero for that bar, etc., I think this is a pretty common practice and as far as I can see and most other codes I've seen, seem to do the same. For a while though, I've noticed, on some products that can get very thin in volatility, on things like range/renko/unirenko bars, you can get bars which essentially have no trades, where liquidity was thin and a new bar formed because price gapped. Ninzarenko is one particular one I find an issue with. It seems that IsFirstTickOfBar does not get set in one of these gap bars, so your code has no idea a new bar has formed. This causes issues with averages etc. Weird thing is, IsFirstTickOfBar DOES fire historically, just not in realtime.
Simple test - I put a draw.diamond call in 'OnFirstTickOfBar'. See image below
no diamond - But, after f5 to reload the chart
It's there. So, this issue only happens in realtime it seems. I'm not 100% sure if this is a problem with the Ninza NinzaRenko bars, or a flaw with my assumption that I should use IsFirstTickOfBar to detect a new bar. The latter does seem like a broken assumption to me, given no ticks (trades) actually occurred in the bar, but on the other hand, it works historically and everyone else seems to do the same, including ninja supplied code.
So, I guess, what is the best way to detect the formation of a new bar. I know most code I see tends to use IsFirstTickOfBar, but it seems in this case, is not a reliable method. What would you suggest? Monitor 'CurrentBar' for changes perhaps? CurrentBar would increment, even with no ticks? If you think this is an issue with the bar type, perhaps you could report it to your vendor ( I think they may be active on this forum and are an active partner with you ).
[edit : as an afterthought, given I experienced this issue, I am wondering, does an indicator get called, even if set to 'OnEachTick', if there are bars with no trades, and no ticks? Because this could result in plot[0] not having any value for that bar?]
Thanks.

Comment