I've seen a few posts on accessing indicators that are on a chart from within a strategy that has subsequently been attached to the chart. While it seems to be possible to access the chart indicators from the indicators collection, some users have reported that this sometimes works and sometimes doesn't. One indicated that it only worked consistently as long as the indicators were added after the strategy. Is this true, as in, would this be expected behavior?
If so, then my question would be, if you use AddChartIndicator() in a strategy to add the desired indicators, would those indicators reliably be accessible to the strategy's NinjaScript via the indicators collection?
A follow-up question would be about doing things in the right order. If an indicator is added via AddChartIndicator in the DataLoaded state change, at what point and in which block of code is it safe to loop through the indicators collection, set a local variable of the type of the indicator to the instance added to the chart, and begin accessing its values?
And the last piece, that I can think of, is would there be any need to call Update() on the indicators in the strategy's OnBarUpdate() method before accessing their values? I'm thinking not since they're on the chart and theoretically would be in sync with the strategy, but, don't want to assume anything.
Thanks,
Gordon
Comment