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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      49 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      69 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      36 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      96 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      59 views
      0 likes
      Last Post PaulMohn  
      Working...
      X