I want to access the price value of a manually inserted horizontal line from an indicator, but without success. I'm using a code snippet I found on the documentation.
This is the code that generates a casting error:
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) {
foreach (Gui.NinjaScript.IChartObject thisObject in ChartPanel.ChartObjects) {
Print(String.Format("There is the object {0} of type {1}", thisObject.Name, thisObject.GetType()));
if (thisObject.GetType().ToString() == "NinjaTrader.NinjaScript.DrawingTools.HorizontalLine") {
Print(String.Format("Accessing the object {0} of type {1}", thisObject.Name, thisObject.GetType()));
NinjaTrader.NinjaScript.DrawingTools.HorizontalLine hl = (NinjaTrader.NinjaScript.DrawingTools.HorizontalLine) thisObject;
stopValue = hl.EndAnchor.Price;
Print(String.Format("{0} is the stopValue", stopValue));
}
}
}
-------------------------------------
There is the object Horizontal Line of type NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e
Accessing the object Horizontal Line of type NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e
Indicator 'JTrader': Error on calling 'OnRender' method on bar 398: Impossibile eseguire il cast di [A]NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e a [B]NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e. Il tipo A ha origine da '01114480d21a40bcb3fce4e44d3c0a38, Version=8.0.7.1, Culture=neutral, PublicKeyToken=null' nel contesto 'LoadFrom' nella posizione 'D:\Documenti\NinjaTrader 8\tmp\01114480d21a40bcb3fce4e44d3c0a38.dll'. Il tipo B ha origine da 'f17f71556d69481983abea6394adb227, Version=8.0.7.1, Culture=neutral, PublicKeyToken=null' nel contesto 'LoadFrom' nella posizione 'D:\Documenti\NinjaTrader 8\tmp\f17f71556d69481983abea6394adb227.dll'
-------------------------------------
I don't get why the casting error occurs, the instance thisObject is of the same type of the casting.

Comment