Moving AveragesPine Script v6

ta.rma()Relative Moving Average (Wilder's Smoothing)

ta.rma() computes Wilder's Relative Moving Average with alpha = 1 / length. Its length must be a simple integer, and Pine uses this smoothing method inside indicators such as RSI and ATR.

Pine Script v6 reference verified: · TradingView reference

Syntax

Syntax
ta.rma(source, length) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries of values to process.
lengthsimple intSmoothing length; alpha = 1 / length.

Returns

Exponential moving average of source with alpha = 1 / length.

Remarks

na values in the source series are ignored, and the function calculates across the requested number of non-na values. The built-in length argument is a simple int, so it cannot vary from bar to bar.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.rma")
plot(ta.rma(close, 15))

//the same on pine
pine_rma(src, length) =>
    alpha = 1/length
    sum = 0.0
    sum := na(sum[1]) ? ta.sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])
plot(pine_rma(close, 15))

Trading Applications

Foundation for RSI calculation (used internally by ta.rsi)

Smoother than EMA with less sensitivity to price spikes

Calculate Average True Range (ATR) components

Build Wilder's directional movement indicators

Frequently Asked Questions

ta.rma() implements Wilder smoothing: each step updates a running average with alpha = 1/length. It matches the smoothing convention used in many classic technical analysis formulas.

The standard RSI averages gains and losses with Wilder smoothing. In Pine Script, ta.rsi uses that convention internally; understanding ta.rma() helps when you replicate or extend RSI-style logic.

Both are recursive smoothers, but they use different alpha: EMA uses 2/(length+1) while RMA uses 1/length. RMA is slower to adapt for the same nominal length and matches Wilder-type indicator specs.

No. rma2() is provided by TradingView's separately imported ta library, not by Pine's built-in ta namespace. It is an alternate RMA that accepts a series float length; the call prefix depends on the alias used when importing the library.

No. The built-in ta.rma() signature requires a simple int length, which is fixed rather than series-based. Use a separately imported implementation that explicitly supports a series length only when that behavior is required.

Generate ta.rma() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.rma() and other built-in functions instantly.