Pine Script RMA Calculator & Code Generator
Generate professional Relative Moving Average (RMA) indicators using Wilder's smoothing method. Our free Pine Script code generator creates RMA indicators identical to SMMA, perfect for RSI calculations and smooth trend analysis in TradingView.
Note: This generated code is a basic indicator template. Always test scripts thoroughly before using them in a live trading environment. Read our disclaimer for more information.
What is the Relative Moving Average (RMA)?
The Relative Moving Average (RMA), also known as Wilder's Moving Average, is a smoothing technique developed by J. Welles Wilder Jr. for use in technical indicators like the RSI (Relative Strength Index) and ATR (Average True Range). The RMA provides extremely smooth results by using a specific exponential smoothing method.
What makes RMA unique is its smoothing factor: alpha = 1/length, which is different from the standard EMA formula. This creates a much smoother moving average that considers all historical data with gradually decreasing weights. The RMA formula is: RMA = (Previous RMA × (length-1) + Current Price) / length.
In Pine Script, ta.rma(source, length) and ta.smma(source, length) are functionally identical - both implement Wilder's smoothing method. This makes RMA perfect for creating indicators that require consistent, smooth calculations without excessive noise.
The Relationship Between RMA and SMMA in Pine Script
One of the most important concepts to understand in Pine Script is that RMA and SMMA are identical functions. Both ta.rma() and ta.smma() implement the exact same Wilder's smoothing algorithm, making them interchangeable in your code.
ta.rma() Function
- • Named after "Relative Moving Average"
- • Commonly used in RSI calculations
- • Implements Wilder's smoothing method
- • Alpha = 1/length
- • Identical to ta.smma() internally
ta.smma() Function
- • Named after "Smoothed Moving Average"
- • More descriptive of its smoothing nature
- • Same Wilder's smoothing algorithm
- • Alpha = 1/length
- • Identical to ta.rma() internally
This equivalence means you can use either function depending on your preference or the context of your indicator. Many traders prefer ta.rma() when building RSI-related indicators and ta.smma() for general trend analysis, but functionally they produce identical results.
Where is RMA Used in Trading Indicators?
RMA is the foundation of several critical technical indicators, particularly those developed by J. Welles Wilder Jr. Understanding these applications helps you appreciate why RMA's smooth characteristics are so valuable:
RSI (Relative Strength Index)
//@version=5
indicator("Custom RSI using RMA", shorttitle="RSI-RMA")
length = input.int(14, title="RSI Length")
src = input.source(close, title="Source")
// Calculate price changes
change = ta.change(src)
gain = ta.rma(math.max(change, 0), length) // RMA of gains
loss = ta.rma(-math.min(change, 0), length) // RMA of losses
// Calculate RSI
rs = gain / loss
rsi = 100 - (100 / (1 + rs))
plot(rsi, title="RSI", color=color.purple)
hline(70, "Overbought", color=color.red)
hline(30, "Oversold", color=color.green)ATR (Average True Range)
//@version=5
indicator("Custom ATR using RMA", shorttitle="ATR-RMA")
length = input.int(14, title="ATR Length")
// Calculate True Range
tr = math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1]))
// Apply RMA smoothing to True Range
atr = ta.rma(tr, length)
plot(atr, title="ATR", color=color.orange)
// Optional: Show ATR as percentage of price
atr_percent = (atr / close) * 100
plot(atr_percent, title="ATR %", color=color.blue, display=display.data_window)RMA Trend Following System
//@version=5
indicator("RMA Trend System", overlay=true)
fast_length = input.int(10, title="Fast RMA Length")
slow_length = input.int(30, title="Slow RMA Length")
// Calculate RMAs
fast_rma = ta.rma(close, fast_length)
slow_rma = ta.rma(close, slow_length)
// Plot RMAs
plot(fast_rma, title="Fast RMA", color=color.blue, linewidth=2)
plot(slow_rma, title="Slow RMA", color=color.red, linewidth=2)
// Trend detection
bullish_trend = fast_rma > slow_rma
bearish_trend = fast_rma < slow_rma
// Background coloring
bgcolor(bullish_trend ? color.new(color.green, 95) : color.new(color.red, 95))
// Crossover signals
bullish_cross = ta.crossover(fast_rma, slow_rma)
bearish_cross = ta.crossunder(fast_rma, slow_rma)
plotshape(bullish_cross, title="Bullish Cross", style=shape.triangleup,
location=location.belowbar, color=color.green, size=size.small)
plotshape(bearish_cross, title="Bearish Cross", style=shape.triangledown,
location=location.abovebar, color=color.red, size=size.small)