Sidechair

ta.rma()

Browse the reference

Returns the running moving average, the smoothing used inside ta.rsi and ta.atr, with a factor of 1 / length.

Try it in the editor

ta.rma applies rma = (source + (length - 1) * rma[1]) / length, which is an exponential average with alpha = 1 / length. It reacts more slowly than ta.ema of the same length, because alpha is smaller.

The first value is the simple average of the first length values of source. If source goes na, the output is na until length valid values arrive to seed it again.

Syntax

Pine Script
ta.rma(source: series int/float, length: simple int) -> series float

Arguments

NameTypeDefaultDescription
sourceseries int/floatrequiredSeries of values to smooth.
lengthsimple intrequiredSets the smoothing factor alpha = 1 / length. A whole number of 1 or more.

Returns

series float: the running moving average, or na until length values of source exist.

Remarks

  • Wilder's indicators (RSI, ATR, ADX) use this average. An ta.ema with length 2 * n - 1 gives nearly the same curve as ta.rma(source, n).
  • Like every recursive average, early values depend slightly on how much history is loaded.

Example

Pine ScriptRMA against EMA of the same lengthOpen in editor
//@version=6
indicator("RMA vs EMA", overlay = true)
len = input.int(14, "Length", minval = 1)
plot(ta.rma(close, len), "RMA", color = color.purple)
plot(ta.ema(close, len), "EMA", color = color.orange)

See also

Runs on Sidechair