PDA

View Full Version : FirstTickOfBar executed twice


MJT
03-25-2009, 08:57 AM
While debugging a problem, I've come accross something that does not look right. The indictor runs with CalculateOnBarClose = false, and uses FirstTickOfBar to perform some tracking that must only be done once per bar.
The chart is setup before a session start time (not yet updating with realtime data), then on the first bar of the new session the code that runs within FirstTickOfBar is executed twice on that bar. This can cause my tracking variables to hold incorrect values. If the indicator is reapplied during the session, then it will only perform FirstTickOfBar once on that first bar. I have used Tick and Range chart types, Ninja version is 6.5.1000.8
I beleive I now have a work-around, but is this a bug or expected behavoir?

NinjaTrader_Bertrand
03-25-2009, 09:16 AM
Hi MJT, thanks for the post - do you have sample code to post so I can reproduce and check it on my end?

MJT
03-25-2009, 10:03 AM
Yes Bertrand,
This should only print to the output window if FirstTickOfBar occurs more than once on the same bar. Set chart session start time to later than current time. Apply indicator, and wait for the session to start.

NinjaTrader_Bertrand
03-25-2009, 10:29 AM
Hi MJT, thanks for bringing this to our attention, I could reproduce this on 6.5

MJT
03-26-2009, 03:41 AM
Thank you Bertrand. I am surprised this has not been identified before, and have been trying to identify the odd behavoir for a long time assuming it was due to an error in my programming.
Is there a suggested work-around for this?

NinjaTrader_Bertrand
03-26-2009, 07:27 AM
Hi MJT, since you already know how to detect this, you can simply ignore it with return out...

MJT
03-27-2009, 03:25 AM
I have now found several other cases in my indicator and in others where this bug causes errors, although most have gone unnoticed in the past. I have now made my own method (using that same bar counting logic), and replaced all instances of FirstTickOfBar.
That is a more reliable and acutally easier to manage work-around.

NinjaTrader_Bertrand
03-27-2009, 04:55 AM
Hi MJT, sorry for the inconvenience caused and great you found a workable solution.