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 CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      213 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      126 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      145 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      229 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      190 views
      0 likes
      Last Post CarlTrading  
      Working...
      X