Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Moving Average Variable input

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

    Moving Average Variable input

    I am wondering how I go about having a field in an indicator that is part of a formula and is changeable from the Parameters section?
    ie.
    ma.Set(ma1(period1)[0];
    I can do the period without a problem by using:
    private int period1 = 4; in the Variables section.
    I am stuck with the ma1?
    I have tried this:
    private ma1 = SMA; but this does not work.
    I want to be able to type in the MA into the field and it then applies it tot he formula.
    Thanks

    #2
    vast524, I would suggest using an enum / switch for this - http://www.ninjatrader-support2.com/...ead.php?t=3420

    Comment


      #3
      Thanks. If I wanted to have multiple MA's would I need to use a specific enum/switch for each MA or can I use the one enum/switch and call it multiple times.
      ie. public enum UniversalMovingAverage1
      {
      EMA,
      HMA,
      SMA,
      WMA,
      }
      public enum UniversalMovingAverage2
      {
      EMA,
      HMA,
      SMA,
      WMA,
      }

      Comment


        #4
        Correct, in your case you would need to enums then to be able to set for example two different MA's with a user switch in your script, if you need more MA's to be selectable, you can of course add them...

        Comment


          #5
          I am still having an issue.
          Here is my formula.
          ma.Set(ma1(ma2(ma3(period3), period2), period1)[0]);
          The period is fine, I just want o be able to enter the ma1, ma2 and ma3 either manually in parameters or as a drop down box.
          I tried the enum/switch but it adds the period ma type. So I can't seem to seperate the periods.

          // If the matype is defined as a WMA then...
          case UniversalMovingAverage.WMA:
          {
          // Sets the plot to be equal to the WMA's plot
          Value.Set(WMA(Period)[0]);
          break;
          }

          Regards

          Comment


            #6
            You would then need to change the enum / switch sample code to include your period / ma tpye combinations.

            Comment


              #7
              So it is possible to have a separate variable for the period and the MA?
              ma.Set(ma1(ma2(ma3(period3), period2), period1)[0]);
              Not quite sure if it possible.

              Comment


                #8
                Are you looking for something like the attached? Same concept, but double MA of the different types used, both with user input period? Of course extendable easily to more MA's as needed....
                Attached Files

                Comment


                  #9
                  Originally posted by NinjaTrader_Bertrand View Post
                  Are you looking for something like the attached? Same concept, but double MA of the different types used, both with user input period? Of course extendable easily to more MA's as needed....
                  Yes this is close. I would like to have the (EMA(EMA(Period1), Period2)[0]); section as a variable. So that I could chose EMA(HMA or SMA(TEMA ..... What ever MA's I had added to the Enum.
                  But to achieve this, must I enter every combination I want in the switch?
                  The period can be achieved easily with a private int.
                  I was hoping for something similar with the MA's.

                  Comment


                    #10
                    I don't believe this is possible, you would need to add the combinations you need to the switch / enum then...

                    Comment


                      #11
                      Can I have an empty field that I have to type in the actual MA type in.
                      So in parameters I would have Period1, Period2 with default settings.
                      But have MA1 and MA2 as fields that can be manually typed in rather than a drop box.
                      So similar to a int but for text.

                      Comment


                        #12
                        vast524,

                        You would create a string parameter and then in your code just check for specific string values like EMA or SMA.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Not sure about these. Any tips?
                          Never used them.
                          Regards

                          Comment


                            #14
                            Unfortunately we don't have a sample for this, you would just check then if your string input contains a certain string value -

                            Code:
                            if (string == "SMA")

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            593 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            343 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            103 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            556 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            554 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X