Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Truncated Moving Average

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

    Truncated Moving Average

    Hello all,

    I am trying to create a simple moving average where the lines don't extend throughout all the past candlesticks.

    I would like to amend the Ninjatrader built-in SMA script to add a user input for how many bars to display the moving average line - that would be the only change.

    For example, I'd like a 5 period SMA but I want to be able to set how many bars the actual moving average line appears on in addition to the current bar that the market is trading on - so for example, if I set the input to 10 that means that it would be a 5 period SMA and the actual line would show on the most recent 10 bars, then after that the moving average line would be gone.

    I am not sure how to add this functionality to the Ninjatrader built-in SMA indicator, any help is greatly appreciated.


    #2
    Hello jmezz,

    That is possible however it would require editing the code for the indictor. In order to keep the value actually calculating you would have to disable rendering and then do a custom rendering for the SMA. There is not a simple example that I could provide in that case as it would require using OnRender to replot the indicator values for specific bars. You can learn about OnRender here:

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello jmezz,

      That is possible however it would require editing the code for the indictor. In order to keep the value actually calculating you would have to disable rendering and then do a custom rendering for the SMA. There is not a simple example that I could provide in that case as it would require using OnRender to replot the indicator values for specific bars. You can learn about OnRender here:

      https://ninjatrader.com/support/help...8/onrender.htm
      Hmm.

      What I’m really trying to do is just plot a little horizontal line at the midpoint of each candle. I read another thread here where it was suggested to use the SMA and set plot style to “Median.”

      Would it be more simple to code an indicator to plot a line vs change the SMA indicator?

      I’ve done most of my coding in Thinkscript which is elementary compared to real coding that Ninja uses haha.

      Comment


        #4
        Hello jmezz,

        It would be more simple in this use case to do that, you could draw a few lines using drawing objects instead of plotting and that would let you continuously update those lines so you only have a few on the chart. Using the same tag name when calling the drawing will update it and move it to the new bar and price.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X