Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Distance from Moving Average

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

    Distance from Moving Average

    Is there an existing indicator that will monitor the distance between the current price and a Moving Average?

    I have completed several search variations but without success.

    Any suggestions on this?

    Thanks!

    JJ

    #2
    Hi JJ,

    I'm not aware of this but you can create easily enough. The following line sets a plot using the absolute value of the difference between close and a SMA.

    Value.Set(Math.Abs(Close[0] - SMA(Close, 14)[0]));
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Prov1322 View Post
      Is there an existing indicator that will monitor the distance between the current price and a Moving Average?

      I have completed several search variations but without success.

      Any suggestions on this?

      Thanks!

      JJ
      And if you want to see it as an oscillator, just yank the "Math.Abs" from Ryan's post thusly:

      Code:
      Value.Set(Close[0] - SMA(Close, 14)[0]);

      Comment


        #4
        Thanks to both RyanM and koganam for the code lines...now just have to figure out how to cut/paste/create from a built-in, system indicator...(and I will...!)

        JJ

        Comment


          #5
          Hello guys!

          Maybe anybody knows if there already is an Indicator that will monitor the distance between price and EMA maybe displayed as a histogram?

          Thank you

          Comment


            #6
            Hello eisi83,

            Thanks for your post.

            I am not aware of an indicator that provides this but you are welcome to review any of the free NT user apps here: https://ninjatraderecosystem.com/user-app-share/ Please note: The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

            If you would like an indicator created for you, we can provide references to 3rd party providers of that service.

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thank you Paul,

              I got what i wanted with a simple MACD showing me exactly what i was looking for.

              Comment


                #8
                I am trying to do this as well. I used the wizard and then pasted the above formula to the logic, but getting this error. I've attached the script, please help me, what am I missing.
                I want to plot below the graph a line of the distance between price and a 233 period EMA. Want the period to be input parameter for indicator.
                I want to set variable ie "PointsAway" to mark a level or plot a horizontal line, so i can easily see and alert if price is greater than 10 points from EMA.
                'NinjaTrader.NinjaScript.Series<double>' does not contain a definition for 'Set' and no extension method 'Set' accepting a first argument of type 'NinjaTrader.NinjaScript.Series<double>' could be found (are you missing a using directive or an assembly reference?)
                Attached Files

                Comment


                  #9
                  Hello AtomRob,

                  Welcome to the NinjaTrader forums!

                  NinjaTrader 7 used DataSeries.Set(). NinjaTrader 8 does not.

                  Value.Set() is how a plot series (Value) would be assigned in NinjaTrader 7

                  To set a value in NinjaTrader 8, directly assign the value.

                  PointsAway = Math.Abs(Close[0] - EMA(Close, EMAperiod)[0]);

                  Or to set a plot:
                  Value[0] = Math.Abs(Close[0] - EMA(Close, EMAperiod)[0]);
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thank you for quick reply,

                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hello AtomRob,

                    Welcome to the NinjaTrader forums!

                    NinjaTrader 7 used DataSeries.Set(). NinjaTrader 8 does not.

                    Value.Set() is how a plot series (Value) would be assigned in NinjaTrader 7

                    To set a value in NinjaTrader 8, directly assign the value.

                    PointsAway = Math.Abs(Close[0] - EMA(Close, EMAperiod)[0]);

                    Or to set a plot:
                    Value[0] = Math.Abs(Close[0] - EMA(Close, EMAperiod)[0]);
                    I tried both of the above seperately, and still can't plot a line of PointsAway.
                    I get this error ( see screenshot, ) , I enter value in properties and still no plot.
                    Click image for larger version

Name:	image.png
Views:	506
Size:	4.5 KB
ID:	1225718

                    Comment


                      #11
                      Hello AtomRob,

                      Looks like you have a public property called PointsAway that is using the Range attribute starting at 5. May I confirm you are defaulting the value of this to 5 in State.SetDefaults?

                      Are you ensuring that you are only assigning a value of 5 or greater to the property in OnBarUpdate() using Math.Max()?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        NinjaTrader_ChelseaB Ok, I set default to 5 like you suggested and i dont' get error but i dont' get anything on chart either.
                        See screenshot notice how chart is showing .1 , .2 And actual value in tick chart is couple points of ES. the Green dotted line is the 233 EMA. I've attached the script as it stands now.
                        Click image for larger version

Name:	image.png
Views:	557
Size:	118.9 KB
ID:	1225848

                        Comment


                          #13
                          Hello AtomRob,

                          Debug the script using Print() to understand the behavior.



                          Print the time of the bar, and all values used in the condition with labels for each value and each comparison operator.

                          Save the output to a text file, include the output with your reply and we will be happy to assist with analyzing the output.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            NinjaTrader_ChelseaB , so I tried to add following Print statement. Here is the OnBarupdate section.
                            I get error "Cannot apply indexing with .to an expression of type "double". Then when i remove the double statement , I get other errors.

                            ===========================================
                            protected override void OnBarUpdate()
                            {
                            //Add your custom indicator logic here.
                            double PointsAway = 5;
                            int EMAperiod = 233;

                            //Value.Set(Math.Abs(Close[0] - EMA(Close,EMAperiod)[0]));
                            PointsAway = Math.Abs(Close[0] - EMA(Close, EMAperiod)[0]);

                            Print(string.Format("{0} | PointsAway[1]", Time[0],PointsAway[1]));

                            //Value[0] = Math.Abs(Close[0] - EMA(Close, EMAperiod)[0]);
                            ​=====================================

                            Comment


                              #15
                              Hello AtomRob,

                              PointsAway is declared as a double which is a number with a decimal. That is not a series and is not an array or any kind of collection. You cannot use an index [1] on a number. You can only use an index on a collection.

                              Remove the index, this is not an array and not a series.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by arvidvanstaey, Today, 02:19 PM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Zachary  
                              Started by mmckinnm, Today, 01:34 PM
                              3 responses
                              5 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by f.saeidi, Today, 01:32 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post f.saeidi  
                              Started by alifarahani, 04-19-2024, 09:40 AM
                              9 responses
                              55 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              3 responses
                              60 views
                              0 likes
                              Last Post NinjaTrader_SeanH  
                              Working...
                              X