At the very bottom of the "AddChartIndicator()" method documentation at https://ninjatrader.com/support/help...tindicator.htm it states:
protected override void OnStateChange() { if (State == State.DataLoaded) { // Charts a 20 period simple moving average to the chart AddChartIndicator(SMA(20)); } } protected override void OnBarUpdate() { // call SMA() historically to ensure the indicator processes its historical states as well double sma = SMA(20)[0]; }
Question #1: Is the problem mentioned above (that is, "otherwise your indicator will only process in State.RealTime for performance optimizations") merely a visual problem, or could it cause the indicator values to be wrong in the code of a Strategy? Is this a dangerous problem for NinjaScript programs that place trades?
Question #2: To avoid the problem mentioned above, does the indicator have to be used in every single OnBarUpdate() call, even the first one (where CurrentBar == 0), or does it only need to be called once in the lifetime of the strategy? If it only needs to be called once, does it matter on which bar, or must it be the first one? In the example from the documentation above it is called on every bar update, even though an indicator might not be valid until the 20th bar.
Thank you in advance!
EquityTrader
Comment