TradingView indicator guides

RMA in Pine Script: Smoothing, Seeds and Slope

Pine Script’s ta.rma applies Wilder-style recursive smoothing with a coefficient of 1/length. The example below plots it on close with editable length and source. The recurrence explains its memory and its relationship to EMA; it does not establish a universal ranking of trading signals.

Inspect the Pine Script

Initialization and the recursive update

For length N, RMA first uses an N-observation simple average to initialize its state, then updates with coefficient alpha = 1/N. With complete input data, length 9 therefore needs nine observations for its initial value. A zero-seeded recursion would be a different calculation.

alpha = 1 / N
R(t) = alpha × source(t) + (1 − alpha) × R(t−1)
R(t) − R(t−1) = [source(t) − R(t−1)] / N

The Pine reference for ta.rma documents the function. TradingView’s RSI explanation also uses RMA on gains and losses. That is different from taking an RMA of price: the input series and the later ratio determine the RSI output.

Length controls the coefficient and initialization window; it is not a hard cutoff for all later history. Once seeded, the state retains geometrically decaying influence from earlier observations. Missing input data should be checked explicitly when comparing implementations, rather than silently replacing absent prices with zero.

Match the EMA coefficient without confusing the seed

EMA uses alpha = 2/(M + 1). Setting M = 2N − 1 matches RMA’s coefficient. Thus RMA9 matches EMA17’s recurrence coefficient, RMA14 matches EMA27, and RMA21 matches EMA41—not EMA21.

Identical coefficients give identical subsequent values only when the starting state and inputs also match. Pine’s ordinary EMA starts from a first-value seed, while RMA waits for its simple-average seed. With complete common inputs after initialization, a difference between those states shrinks by (1 − 1/N) on each update; it does not vanish merely because the coefficients agree.

At length 9, the current-source weights are 1/9 for RMA and 1/5 for EMA9. Their ratio is 1.8, but that is a coefficient comparison, not a measured “1.8 times smoother” score, fixed entry delay or false-signal reduction. A trading result also depends on the exact rule and data.

A five-observation initialization check

Take synthetic sources 100, 103, 106, 109, 112 and set N = 3. RMA is unavailable for the first two observations; its third value is their three-observation mean, 103. Its next values are 105 and 107.333333.

SourceRMA3EMA5, first-value seedDifference
100na100na
103na101na
106103102.6666670.333333
109105104.7777780.222222
112107.333333107.1851850.148148

Both recursions use 1/3 after the RMA seed, and their difference contracts by 2/3. These are arithmetic fixtures, not historical prices or performance measurements. Matching the loaded history matters when diagnosing differences near startup.

Source position and one-bar slope are linked

For an initialized RMA, complete inputs and N greater than 1, the recurrence gives a second identity:

source(t) − R(t) = (1 − alpha) × [source(t) − R(t−1)]
R(t) − R(t−1) = alpha × [source(t) − R(t−1)]

Both coefficients are positive. Therefore source above the current RMA and a positive one-bar RMA slope are equivalent sign conditions. With source = close, close cannot be above that same RMA while it is falling on that update. Adding this slope test to a same-bar close-above condition does not provide an independent filter.

The statement changes if the selected source is HL2 but the comparison uses close, if you compare a multi-bar slope, shift the plot, or use a different timeframe. At N = 1, RMA equals the valid source, so a strict source-above test never holds even though the source and line can rise.

A crossover additionally needs the previous pair relationship. “Above” is a state, not a new cross on every bar. The displayed slope angle also depends on chart scaling; use value differences and specified units rather than treating a screen angle as a stable strength measurement.

Memory, source choice and practical boundaries

Assume RMA9 is settled at 100. A single source observation of 109 moves it to 101. If subsequent sources return to 100, the excess becomes 8/9, then (8/9)², and continues decaying. After nine further valid updates, about 34.64% of that initial excess remains. A nine-period RMA on a four-hour chart therefore does not contain only the last 36 hours.

With close selected, an intrabar wick that leaves the final close unchanged does not directly enter the closed-bar calculation. Changing to HL2 introduces high and low into the source; it does not universally reduce the effect of wicks. During an open bar, the chosen source and RMA can still change.

The copy exposes length and source, draws one blue line, and has no alert conditions, trade orders, higher-timeframe requests or bar-close gate. The default of 9 is an example setting, not a verified best length. For a trading test, specify event timing, exits, costs and evaluation data separately. No strategy win rate is established here.

Pine Script v6: implementation and limits

The original minimal Pine Script v6 example below is retained. Its editable inputs default to length 9 and close, and ta.rma supplies the calculation.

Pine Script v6
//@version=6
indicator(title="Rolling Moving Average", overlay=true, max_labels_count=500)

// Inputs
length = input.int(9, "Length", minval=1)
src = input.source(close, "Source")

// RMA Calculation — Wilder's Smoothing
rma_val = ta.rma(src, length)

// Plot
plot(rma_val, "RMA", color.rgb(41, 98, 255, 0), 2)
Existing indicator chart preview
Existing visual preview. Verify exact values against the source; the image is not a performance result.

Specify a checkable adaptation in Pineify

Ask the Pine Script AI Coding Agent for a specified length, source and confirmation policy. Include the initialization table and same-source slope identity as checks. If requesting alerts, distinguish a continuing above-line state from a first crossover; validate generated code before defining strategy execution.

Open Pine Script AI Coding Agent

Educational indicator analysis. No measured trading performance is established here. Syntax validation does not prove formula equivalence, execution assumptions or profitability.

Implementation questions

They use the same recursive coefficient, but their built-in initialization differs. Matching source, state and subsequent inputs is necessary for exact equality; a seed difference decays over later updates.

For an initialized unshifted RMA, complete data and length greater than 1, not on the same one-bar update. Both signs depend on close minus the previous RMA. A different source, timeframe or multi-bar slope changes the comparison.

No. Nine observations initialize it, and later updates retain decaying information from the previous state. It is not a rolling nine-bar SMA.

With close as the source, an unchanged final close contributes the same value regardless of the wick. With HL2 or another source, high and low may affect the calculation. Smoothing does not guarantee removal of a price movement.

No universal ranking is established here. Coefficients, initialization, input data and the test rule must be specified; a smaller update coefficient alone does not prove fewer losing trades.

Yes. It exposes a positive integer length and a source input. Alerts or a strategy require additional code and validation.