Array of function evaluators or a way to speed up evaluation

Topics: General
Nov 14, 2015 at 6:48 AM

my extended funciton evaluator is of the form

private void myEvaluator(string name, FunctionArgs args)
if(name=="A") { // call function to evaluate }
else if(name=="B") { // call function to evaluate }

This works fine but the problem I'm having is that I use the extended function within NinjaTrader which is a trading platform. The evaluator is called for every tick change, and my functions "A, "B", etc... are now up to about 30 and I'm having real performance issues.

This means that for every evaluation I'm doing up to 30 string comparisons just to get to the correction evaluator function. I would like to use either delegates or function pointers so that I can pass the first parameter in args as a function value or pointer, so that I could have an array of delegates or an array of function pointers (preferably because its simpler) so that I could call the correct evaluator function using that parameter.

I've tried various things for both delegates and function pointers but so far I've ended up with compile or runtime errors. There are a couple of restrictions -
  • putting the evaluator function or delegate in a class won't work, because of the way Ninjatrader variables are initialised.
  • I doubt that I can use static functions because the evaluator needs to access non-static variables.
Has anyone else tried this or are there any examples of how I might do this?