Problem / Solution: Hosted indicator values lagging one bar in my strategy

Running a strategy on Calculate.OnBarClose that hosts a custom indicator on a separate Renko series. The strategy reads the indicator’s plot values at entry, but I proved with logs it was always reading the prior completed bar, not the forming one. My gate reported a value that matched the previous bar on the chart, not the bar that was actually forming when the entry fired.

Cause: A hosted indicator inherits the host strategy’s Calculate mode. So even though my indicator sets OnEachTick internally, hosting it inside an OnBarClose strategy forces it to OnBarClose. And in OnBarClose mode, Series[0] references the last closed bar, never the forming one. The indicator was computing the forming bar correctly in its own data, but publishing every value through bar indexed plot Series, so [0] resolved to the prior bar. Both the values and the OHLC agreed on the wrong bar, which is what tipped me off.

Resolution: I stopped reading the values through the bar indexed Series. Instead I added plain public scalar fields on the indicator and write them every tick from inside OnMarketData, straight from the forming bar’s data. OnMarketData fires on every tick for secondary series regardless of Calculate mode, and plain fields have no bar index, so the OnBarClose lag can’t touch them. The strategy reads the scalars instead of [0]. Values now match the forming bar. The plot Series stay untouched for rendering and Market Analyzer.

Key lesson: if you host an indicator in an OnBarClose strategy and need the forming bar’s values, don’t read them through Series[0]. Expose them as scalar fields updated in OnMarketData. (Atleast that was my solution)