I'm using the function below to retrieve the value of an indicator displayed on the chart.
If this code is in OnBarUpdate(), it works perfectly.
If it's outside, it only works partially.
Indeed, indicator.Name is displayed perfectly (I'm displaying the name of the indicator) whereas instead of having plot (the name of the output as displayed in the databox), I have NinjaTrader.Gui.Plot.
Also val is always 0!
Is what I'm looking for possible outside OnBarUpdate()?
If so, what's wrong with my code?
Thank you in advance for your help.
private double GetIndic (string Name,string MyPlot, int index) { double retour = -1; foreach (IndicatorBase indicator in ChartControl.Indicators) { for (int seriesCount = 0; seriesCount < indicator.Values.Length ; seriesCount++) { Plot plot = indicator.Plots[seriesCount]; double val = indicator.Values[seriesCount].GetValueAt(index); if (indicator.Name ==Name) { Print (Name+" "+MyPlot+" "+index+" ---> "+indicator.Name+" "+plot+" "+val); } if (indicator.Name ==Name && plot.Name==MyPlot) retour = val; } } Print (retour); return retour; }
Comment