• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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, 07: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 rouillard, Today, 03:34 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_Tyler  
          Started by mquinteroj, Today, 02:41 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by JPPoulin, Today, 01:32 PM
          4 responses
          15 views
          0 likes
          Last Post JPPoulin  
          Started by bltdavid, Today, 01:09 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by pstrusi, Today, 12:50 PM
          2 responses
          8 views
          0 likes
          Last Post pstrusi
          by pstrusi
           
          Working...
          X