The indicator is updated in the onBarUpdate method. When Calculate = on each tick, onBarUpdate is updated every tick. The problem is that onBarUpdate method is called BEFORE the onMarketData method. If your indicator relies on intrabar calculations done in the onMarketData method your indicator will always be wrong because those calculations are still not updated with the last tick info.
You can test this behavior using the simple indicator attached to this thread. The idea is simply to log some string inside the onBarUpdate method and inside the onMarketData method. You will see that the onBarUpdate executes always before the onMarketData for every tick trade (tick type = last). This is not a multithreading race issue. The log prints statements in the order they were requested to be printed, so log order reflects execution order. Besides I've printed also the managed thread id and it's always the same.
In the NT8 docs it says
The OnMarketData() method is guaranteed to always be called before OnBarUpdate()
which is not true and it contradicts this other fragment in the docs
Calculate.OnEachTick
OnMarketData and OnBarUpdate call for each tick used to build the bar
• 1 OnBarUpdate event on CurrentBar 0
• Followed by 1 OnMarketData event
• 1 OnBarUpdate event on CurrentBar 0
• Followed by 1 OnMarketData event
• 1 OnBarUpdate event on CurrentBar 0
• Followed by 1 OnMarketData event
• 1 OnBarUpdate event on CurrentBar 0
• Followed by 1 OnMarketData event
• ...etc.
My understanding is onBarUpdate should be called always AFTER onMarketData to give the indicator a chance of updating with the most recent tick info.
Right now, onBarUpdate is updated BEFORE onMarketData which kind of defeats the whole purpose of calculating the indicator tick by tick, and thus making Tick Replay almost useless.
Can some expert NT8 developer confirm this issue or guide me on what I might be misunderstanding, please?
This thread a summary of my findings in these two other forums threads:
Comment