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 aussugardefender, Today, 01:07 AM
          0 responses
          1 view
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          238 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          383 views
          1 like
          Last Post Gavini
          by Gavini
           
          Started by oviejo, Today, 12:28 AM
          0 responses
          1 view
          0 likes
          Last Post oviejo
          by oviejo
           
          Started by pechtri, 06-22-2023, 02:31 AM
          10 responses
          125 views
          0 likes
          Last Post Leeroy_Jenkins  
          Working...
          X