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

Declaration of Generic Indicator

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

    Declaration of Generic Indicator

    Hello,

    I am developing a strategy where the user may elect EMA/HMA/SMA as their moving average type.

    I would like to declare a variable that is then assigned to the moving average type selected by the user. For example:

    XXXX myMA; (where XXXX is the variable type)

    If the user selects EMA, myMA is converted from a generic indicator type to EMA. If SMA is selected, myMA becomes a variable of type SMA.

    Is there a generic indicator class to which I can assign myMA before it gets assigned to the user-selected MA type?

    Thank you.

    #2
    Hello ivb73077,

    There is not a generic indicator type you could cast this to. You would need to cast this as the indicator type it is.

    SMA mySMA = (SMA) SMA(14);

    EMA myEMA = (EMA) EMA(14);
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you.

      Comment


        #4
        Originally posted by ivb73077 View Post
        Hello,

        I am developing a strategy where the user may elect EMA/HMA/SMA as their moving average type.

        I would like to declare a variable that is then assigned to the moving average type selected by the user. For example:

        XXXX myMA; (where XXXX is the variable type)

        If the user selects EMA, myMA is converted from a generic indicator type to EMA. If SMA is selected, myMA becomes a variable of type SMA.

        Is there a generic indicator class to which I can assign myMA before it gets assigned to the user-selected MA type?

        Thank you.
        You can always use a base class as a generic declaration for an inherited class. So, it is not a NinjaTrader supported method, (caveat emptor), but you can declare XXX as IndicatorBase.
        Last edited by koganam; 08-05-2015, 08:03 AM. Reason: Corrected programming jargon.

        Comment


          #5
          This is exactly what I was looking for.

          I was not clear what type to declare the generic case because I did not know about the IndicatorBase class. Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by lorem, Yesterday, 09:18 AM
          4 responses
          13 views
          0 likes
          Last Post lorem
          by lorem
           
          Started by Spiderbird, Today, 12:15 PM
          0 responses
          5 views
          0 likes
          Last Post Spiderbird  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          12 responses
          42 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by FrazMann, Today, 11:21 AM
          0 responses
          6 views
          0 likes
          Last Post FrazMann  
          Started by geddyisodin, Yesterday, 05:20 AM
          8 responses
          52 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X