Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

delegate usage with EMA

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    delegate usage with EMA

    I'm wrestling with delegates and data types ... is there an example I could take a look at? Here is some simple code that does not work:
    Code:
    private delegate Indicator foo(Series<double> d, int i);
    ...
    foo foo2 = EMA;
    double d = foo2(Inputs[0], 10)[0];
    That fails on Inputs[0] with the error message:
    Argument 1: cannot convert from 'NinjaTrader.NinjaScript.ISeries<double>' to 'NinjaTrader.NinjaScript.Series<double>'
    The problem seems to be with my delegate usage because the following code, which should be equivalent, compiles just fine:
    Code:
    double dd = EMA(Inputs[0], 10)[0];

    #2
    The error message indicates you should try,

    private delegate Indicator foo(ISeries<double> d, int i);

    Does that work?

    Comment


      #3
      That's embarrassing. I could swear that I tried that and there was a problem, which is why I posted. It seems to be working now, and I deleted the failing code, so I don't know what I did differently before. Thanks.

      It's not allowing me to do anything I could not do before, but it's much nicer code -- it allows eliminating some ugly nested switch statements.
      Last edited by ETFVoyageur; 05-18-2024, 02:27 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      607 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      353 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      560 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      561 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X