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 cre8able, Yesterday, 01:16 PM
          3 responses
          11 views
          0 likes
          Last Post cre8able  
          Started by ChartTourist, Today, 08:22 AM
          0 responses
          6 views
          0 likes
          Last Post ChartTourist  
          Started by LiamTwine, Today, 08:10 AM
          0 responses
          2 views
          0 likes
          Last Post LiamTwine  
          Started by Balage0922, Today, 07:38 AM
          0 responses
          5 views
          0 likes
          Last Post Balage0922  
          Started by JoMoon2024, Today, 06:56 AM
          0 responses
          6 views
          0 likes
          Last Post JoMoon2024  
          Working...
          X