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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X