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 Javierw.ok, Today, 04:12 PM
          0 responses
          2 views
          0 likes
          Last Post Javierw.ok  
          Started by timmbbo, Today, 08:59 AM
          2 responses
          10 views
          0 likes
          Last Post bltdavid  
          Started by alifarahani, Today, 09:40 AM
          6 responses
          40 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          18 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X