Is there a property available to NinjaTrader 8 strategies, like LastBarOnChart, that returns true if a bar is the last bar of the chart from the perspective of the Strategy?
If not, how can one determine this in a way that works in all NinjaTrader 8 applications and scenarios, including back-tests in the Strategy Analyzer, applying a strategy to a historical chart that is disconnected from market data, applying a strategy to a live chart with real-time ticks, and all other NinjaTrader 8 windows where the user can apply a strategy to market data, for all 3 choices for StrategyBase.Calculate, including Calculate.OnBarClose, Calculate.OnEachTick, and Calculate.OnPriceChange?
I understand that in the Strategy Analyzer, the last bar from the perspective of the strategy is the second to the last bar that is visible at the far right edge of the chart, and that is OK. I'm not looking for the last visible bar, just the last bar from the perspective of the strategy during the back-test or in a real-time situation.
I saw this post by NinjaTrader_Ray from back in 2007, but it was for NinjaTrader 7, so did not include an option for calculating this property when Calculate = Calculate.OnPriceChange, plus maybe the answer has changed for another reason related to something new in NinjaTrader 8.
The function below is my best guess based on NinjaTrader_Ray's post above, but I am concerned that it won't work in every scenario in NinjaTrader 8 so was hoping for an official answer from NinjaTrader support, and hopefully an official property of StrategyBase like "LastBarOnChart":
public bool IsLastBarOnChart_MayNotWorkInEveryScenario() { return (Calculate == Calculate.OnBarClose && CurrentBar == Bars.Count - 2) || (Calculate != Calculate.OnBarClose && CurrentBar == Bars.Count - 1); }
EquityTrader
Comment