Indicator · Pine Script v6 · Own pane

Rolling Moving Average

by SiegerTerpstra· code credited to sajjetti

This indicator plots a Rolling Moving Average, also called Wilder's smoothing or SMMA, on the price chart.

View on GitHub

GitHub stars5on the repository
Pine versionv6current
Lines of code120
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update9 months ago14 Jan 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

120 lines of Pine Script v6 from 4 - RMA (v6).pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

4 - RMA (v6).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sajjetti

//@version=6

//-------------------------------------

// Release:                     2020-08-05
// Update:                      2025-12-29
// Author:                      sajjetti
// Email:                       contact@sajjetti.ai
// Website:                     sajjetti.ai
// Profile:                     https://www.tradingview.com/u/stmd/
// Pineversion:                 6
// Filename:                    4 - RMA (v6).pine

//-------------------------------------
// PURPOSE
// Rolling Moving Average (RMA) - also known as Wilder's Smoothing or SMMA.
// A smoothed moving average that gives more weight to recent data while
// maintaining a longer memory of past prices than EMA.

//-------------------------------------
// FEATURES
// - Multi-timeframe support via Indicator Timeframe input
// - Wilder's smoothing formula
// - MA-seeded initialization
// - Optional smoothing via additional MA pass
// - Offset parameter for historical analysis
// - Dynamic color based on rising/falling values

//-------------------------------------
// NOTES
// - RMA = (previous RMA * (length - 1) + current price) / length
// - Smoother than EMA, slower to react
// - Used in RSI, ATR, and ADX calculations
// - Alpha = 1/length (vs EMA alpha = 2/(length+1))
// - Commonly used lengths: 9, 14, 21
// - Price above RMA = bullish, below = bearish

//-------------------------------------
// INDICATOR PARAMETERS

vVersion                        = "V2.0"
vPineVersion                    = "ps6"
vTitle                          = "Rolling Moving Average"
vShort                          = "RMA"
vOverlay                        = true
vPrecision                      = 0

indicator( title = vTitle+" ["+vVersion+"|"+vPineVersion+"]", shorttitle = vShort+" ["+vVersion+"|"+vPineVersion+"]", overlay = vOverlay, precision = vPrecision )

//-------------------------------------
// INPUTS

var groupRma                    = "RMA (Standard: close, 9, 1)"

vTimeframe                      = input.timeframe( defval = "", title = "Indicator Timeframe" )
vSource                         = input.source( defval = close, title = "Source", group = groupRma )
vLength                         = input.int( defval = 9, minval = 1, maxval = 1024, title = "Length", group = groupRma )
vSmooth                         = input.int( defval = 1, minval = 1, maxval = 1024, title = "Smooth", group = groupRma )
vOffSet                         = input.int( defval = 0, minval = 0, maxval = 1024, title = "Offset", group = groupRma )

//-------------------------------------
// COLORS

cBullish                        = #26A69A
cBearish                        = #EF5350

//-------------------------------------
// FUNCTIONS

// @function    Simple Moving Average
// @param       n (int) Offset for lookback starting point
// @param       s (series float) Source data
// @param       le (int) Length of the averaging period
// @returns     (float) Average value over the specified period
fMa( n, s, le ) =>
    r = float( 0 )
    for i = n + 0 to ( n + ( le - 1 ) )
        r := ( r + s[ i ] )
    a = r / le
    a

// @function    Rolling Moving Average (Wilder's Smoothing)
// @param       n (int) Offset for source indexing
// @param       s (series float) Source data
// @param       le (int) Length for RMA calculation
// @returns     (float) RMA value with persistent state
fRma( n, s, le ) =>
    ma = fMa( n, s, le )
    var float r = na
    r := na( r[ 1 ] ) ? ma : ( ( r[ 1 ] * ( le - 1 ) ) + s[ n ] ) / le
    r

// @function    Calculate RMA with smoothing for MTF support
// @returns     (float) Smoothed RMA value
fCalcRma() =>
    rmaBase = fRma( vOffSet, vSource, vLength )
    fMa( 0, rmaBase, vSmooth )

// @function    Determines plot color based on trend direction
// @param       n (int) Offset for comparison
// @param       s (series float) Source data to evaluate
// @returns     (color) Green if rising, red if falling
fColor( n, s ) =>
    r = ( s[ n + 1 ] < s[ n ] ) ? cBullish : cBearish
    r

//-------------------------------------
// CALCULATIONS

vRma                            = vTimeframe == "" ? fCalcRma() : request.security( syminfo.tickerid, vTimeframe, fCalcRma() )

//-------------------------------------
// PLOT

vPlotRma                        = plot( vRma, style = plot.style_line, color = fColor( 0, vRma ), title = "RMA" )

//-------------------------------------

Overview

Rolling Moving Average averages the selected source with a length-based Wilder formula that is seeded by a simple moving average, then can apply a second moving-average pass. Length, source, smoothing, offset, and an optional indicator timeframe change the calculation. The line changes color as the average rises or falls. The script does not generate trade entries or exits.

Details

Published by

SiegerTerpstra on GitHub

Code credit

sajjetti, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Moving averages, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

tradingviewindicatorindicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Indicator TimeframetimeframevTimeframe
SourcesourceclosevSource
Lengthint9vLength
Smoothint1vSmooth
Offsetint0vOffSet
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator
99 stars

Calculates the Archer Moving Averages Trends (AMAT) indicator by comparing fast and slow Exponential Moving Averages (EMAs) alongside their slope directions. A bullish trend (+1) is identified when the fast EMA exceeds the slow EMA with both rising, while a be

Indicator v6 TrendMoving averages
Updated 4 weeks ago · Apache-2.0 GitHub repository of Archer Moving Averages Trends (AMAT)

Colored fill

by be-thomas
65 stars

This indicator plots two simple moving averages of close, one over five bars and one over twenty bars, in a separate pane. It shades the area between the two plots green when the shorter average is above the longer average and red when it is below. There are n

Indicator v4 Moving averagesTrend
Updated 4 days ago · GPL-3.0 GitHub repository of Colored fill

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers