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

Centered moving average

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

    Centered moving average

    I have a custom dataseries that is an SMA (of another indicator) with a period of say 9, loaded using the Set method at [0]. This works and plots fine.
    How can I recalculate and offset the plot result so that each latest SMA value (calculated at the current bar) plots at the point of 5 bars ago.
    Note: This isn't just shifting the standard SMA,9 graph line to the left by 5 bars. It should result in a totally different shape plot...often referred to as a "centered" moving average. (However, it will not have values plotted in the latest 5 bars due to the offset.)

    Thanks for your help.
    (BTW, some other platforms offer this as an included indicator).

    #2
    I'm not sure I follow. What you sound like you want to do is place the latest calculated SMA(9) at five bars ago. How is this different from shifting the indicator back 5? Your calculated values aren't changing so how would the graph change?
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Centered moving avaerage

      Josh,
      Sorry...your'e correct...too many late nights at this end.

      In order to shift the plot of my custom dataseries, I tried this:

      mydataseries.Set(SMA(customseries,9)[0]);
      Plot0.Set(mydataseries[5]);

      (if I use [0], I get the standard SMA curve plotted to the current bar, but I want to see the latest value plotted 5 bars back and so forth)

      Any help is appreciated.
      BTW, this is also referred to as a displaced moving average per investopedia.
      ..

      Comment


        #4
        DataSeries.Set(int barsAgo, double value)
        You can also set the value for historical bars by including a "barsAgo" value that represents the number of bars ago that you want the double value to be stored at.
        RayNinjaTrader Customer Service

        Comment


          #5
          Another solution

          Thanks for your help.

          It looks like the "Displacement" function is what I was searching for. It's simple and appears to solve the problem.

          Comment


            #6
            NOTE: Displacement does not work in strategies.

            I also tried to add displacement manually to an indicator and use it in a strategy. It did not function.



            DataSeries.Set(int barsAgo, double value)

            This may work...

            Comment


              #7
              I tried something else...


              I made another indicator to house two SMAs. (sMAl1 & sMAl2 are integers to control period).

              SMAline1.Set(SMA(sMAl1)[0]);
              SMAline2.Set(SMA(sMAl2)[1]);

              This doesn't work for some reason.
              No lines are plotted unless you change the above to: SMAline2.Set(SMA(sMAl2)[0]);


              Is there a reason that you cannot do: SMA(sMAl2)[NumberBesidesZero] ???

              Comment


                #8
                Please see your Control Center logs for errors. You are most likely running into this issue: http://www.ninjatrader-support.com/v...ead.php?t=3170
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Josh,


                  perfect. Thanks.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by cmtjoancolmenero, Yesterday, 03:58 PM
                  1 response
                  17 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by benmarkal, Yesterday, 12:52 PM
                  3 responses
                  23 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by helpwanted, Today, 03:06 AM
                  1 response
                  19 views
                  0 likes
                  Last Post sarafuenonly123  
                  Started by Brevo, Today, 01:45 AM
                  0 responses
                  11 views
                  0 likes
                  Last Post Brevo
                  by Brevo
                   
                  Started by pvincent, 06-23-2022, 12:53 PM
                  14 responses
                  244 views
                  0 likes
                  Last Post Nyman
                  by Nyman
                   
                  Working...
                  X