Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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


        #4
        Hello ETFVoyageur,

        Thanks for your post.

        bltdavid has provided some good information on the topic.

        Please note that using delegate in NinjaScript would go outside the scope of support we would be able to provide you with in the Support Department at NinjaTrader as it would fall under C# education and we do not provide C# education in our support.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by yertle, Today, 11:03 AM
        0 responses
        1 view
        0 likes
        Last Post yertle
        by yertle
         
        Started by yertle, Today, 11:03 AM
        0 responses
        3 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by lcgamarra_pinnacle, Today, 09:33 AM
        0 responses
        13 views
        0 likes
        Last Post lcgamarra_pinnacle  
        Started by MokhtarVerdi, Today, 07:21 AM
        1 response
        9 views
        0 likes
        Last Post MokhtarVerdi  
        Started by chartchart, 05-19-2021, 04:14 PM
        6 responses
        661 views
        1 like
        Last Post mmenigma  
        Working...
        X