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

Automatically Calculate Moving Average Period

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

    Automatically Calculate Moving Average Period

    Hello,

    I have various different tick period moving averages on a chart, but once price moves past all of them, I need to know the next one in order to carry out some calculations. Is there a way to set up a calculation to find the next moving average (period) above price and below price, say using 20 period increments or decreases? Currently I am having to change the time period of my charts until I find the next MA in the right position.

    Thank you.

    #2
    Hello GeorgeW,

    I'm not quite understanding your inquiry.

    Are you saying you want the value of a moving average for the next bar that hasn't opened yet?
    (i.e. trying to predict the future?)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for responding ChelseaB,

      What I am saying is lets say I have a 20, 50 and other periods moving averages on the chart, once price has gone past them, let's say rising in this example, what is the next moving average above it, (80 period, 15 period?) can it be calculated automatically. It will not always be a higher period one, as a much higher period one may be below current price. Similar when price is moving down.

      Comment


        #4
        Hello GeorgeW,

        I still think I do not have a good understanding of your inquiry.

        Are you asking if there are multiple moving averages, and the first added moving average is below the close price, you want to find the moving average with the lowest price that is above the close price from the other moving averages if there is a remaining moving average indicator with a price above the close price, is this correct?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by GeorgeW View Post
          Thanks for responding ChelseaB,

          What I am saying is lets say I have a 20, 50 and other periods moving averages on the chart, once price has gone past them, let's say rising in this example, what is the next moving average above it, (80 period, 15 period?) can it be calculated automatically. It will not always be a higher period one, as a much higher period one may be below current price. Similar when price is moving down.
          You likely have to use a loop on the bar's open, to calculate moving averages until you find the first one that exceeds the reference price.

          Comment


            #6
            Thanks Koganam, I'll give that a try.

            ChelseaB, all I am try to do is find the next periods moving average that would be say 5 pips + above or below price. The way the moving averages that I am using work, I would be looking for the next chart size. So if I am using a 200 Tick chart size, I can see the moving averages for the 400, 600, 800 etc chart size when price comes within a certain distance of them. When there is a very strong trend, price may move past those moving averages. The next chart size for a moving average above or below price is not necessarily in some consistent rising or falling order - e.g. price may rise above 600 and 800 chart moving averages, but the 1,200 chart moving average is still below. Once I have moved past all the moving averages that I have programmed, I am then having to manually try different ones to find the next one that price will hit. I want a way for NT to work that out automatically.

            Comment


              #7
              Hello GeorgeW,

              Thank you for your response.

              I would agree with Koganam here on the approach to looping through the additional series moving averages to find the next one that the Input series would be below.

              Comment


                #8
                Thanks for your input PatrickH,

                To use the looping approach, I would have to decide in advance what chart sizes I wanted to loop through to find the one that equates to the moving average above or below my Input series. I would have thought it should be possible to set up an equation with a price above or below my Input series as the one I wanted to be closest to my moving average price, with the chart size as the unknown to be calculated, and then work it out that way. I just can't figure out what that equation would look like. Any ideas?

                Comment


                  #9
                  Hello GeorgeW,

                  Thank you for your response.

                  Attached is an example that utilizes a Dictionary to allow for looping and comparing the different SMAs added in the code against the Close of the primary bar series to find the closest SMA that is greater than the Close.

                  If you have any questions please let me know.
                  Attached Files

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  2 responses
                  29 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by Mindset, 05-06-2023, 09:03 PM
                  10 responses
                  263 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by michi08, 10-05-2018, 09:31 AM
                  5 responses
                  742 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by The_Sec, Today, 02:29 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post The_Sec
                  by The_Sec
                   
                  Started by tsantospinto, 04-12-2024, 07:04 PM
                  4 responses
                  63 views
                  0 likes
                  Last Post aligator  
                  Working...
                  X