Am using the below code to convert an Indicator to DataSeries
Type type = base.GetType(); MethodInfo mi = type.GetMethod("SMA", new Type[] { Type.GetType("System.Int32") }); DataSeries dataSeries = new DataSeries((IndicatorBase)mi.Invoke(this, new object[] { 14 }));
I did the same for KPMWAP indicator, ( Note that GetTypeFromAllAssemblies() is a method which loop through all assemblies and return Type). In the below code, type and mi is not null but cannot convert into DataSeries
Type type = this.GetTypeFromAllAssemblies("NinjaTrader.Indicator.KPMWAP"); MethodInfo mi = type.GetMethod("KPMWAP", new Type[] { Type.GetType("System.Int32") }); DataSeries dataSeries = new DataSeries((IndicatorBase)mi.Invoke(this, new object[] { 3 }));
Object does not match target type.
So what I did is, I created instance of KPMWAP and used that object instead of this in method invoke
Type type = this.GetTypeFromAllAssemblies("NinjaTrader.Indicator.KPMWAP"); object objKP = Activator.CreateInstance(type); MethodInfo mi = type.GetMethod("KPMWAP", new Type[] { Type.GetType("System.Int32") }); DataSeries dataSeries = new DataSeries((IndicatorBase)mi.Invoke(objKP, new object[] { 3 }));
'dataSeries.Count', threw an exception of type 'System.NullReferenceException'
What is the best way to get the DataSeries of third party indicator?
Comment