Returns the running moving average, the smoothing used inside ta.rsi and ta.atr, with a factor of 1 / length.
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
ta.rma(source: series int/float, length: simple int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | Series of values to smooth. |
| length | simple int | required | Sets 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.emawith length 2 * n - 1 gives nearly the same curve asta.rma(source, n). - Like every recursive average, early values depend slightly on how much history is loaded.
Example
//@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