I'm trying to implement an array of delegates and I was doing pretty well until I ran into a problem.
the code so far...
// in variables section - my indicator name is WillsMTWave, and FunctionArgs is from class NCalc
private FloatSeries[] wmtPlotValues;
delegate void gwExtendedFunction(FunctionArgs args);
gwExtendedFunction[] gwExtendedFunctions;
GWExprEvaluatorFunctions gwExprEvaluatorFunctions;
public class GWExprEvaluatorFunctions : NinjaTrader.Indicator.WillsMTWave {
public void concaveCB(FunctionArgs args) {
Print(wmtPlotValues[0][0].ToString());
}
}
// in Initialize()
wmtPlotValues = new FloatSeries[PLOTS];
gwExprEvaluatorFunctions = new GWExprEvaluatorFunctions();
gwExtendedFunctions = new gwExtendedFunction[3];
gwExtendedFunctions[0] = new gwExtendedFunction(gwExprEvaluatorFunctions.concav eCB);
// in OnBarUpdate()
// call the delegate
gwExtendedFunctions[0](args);
Now, this actually all works fine (almost), I can call the delegate and get some correct debug out, including the parameters, but the line
Print(wmtPlotValues[0][0].ToString());
is giving the runtime error
Error on calling 'OnBarUpdate' method for indicator 'WillsMTWave' on bar 22: Object reference not set to an instance of an object.
bar 22 is the first bar for which it is called. Now strictly speaking the call gwExtendedFunctions[0](args) is not made from within OnBarUpdate(),
it is actually made from another delegate function that is called from within OnBarUpdate(), I'm not sure if thats significant or not. I can correctly reference wmtPlotValues[0][0] from within OnBarUpdate(), its only when its referenced from the delegate that the error occurs.
Anyone game to tackle this one for me?
Thanks,
will.
Comment