ta.rsi()
Relative Strength Index
The rsi function returns the relative strength index. It is calculated using the ta.rma() of upward and downward changes of source over the last length bars.
Syntax
ta.rsi(source, length) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| source | series int/float | Price or value series (commonly close). |
| length | simple int | Lookback length for averaging gains and losses. |
Returns
Relative Strength Index.
Remarks
na values in the source series are ignored.
Code Examples
//@version=6
indicator("ta.rsi")
plot(ta.rsi(close, 7))
// same on pine, but less efficient
pine_rsi(x, y) =>
u = math.max(x - x[1], 0)
d = math.max(x[1] - x, 0)
rs = ta.rma(u, y) / ta.rma(d, y)
res = 100 - 100 / (1 + rs)
plot(pine_rsi(close, 7))Trading Applications
Identify overbought (>70) and oversold (<30) conditions
Detect bullish/bearish divergences
Use RSI crossovers for entry signals
Combine with trend indicators for filtered signals
Related Functions
Frequently Asked Questions
Generate ta.rsi() Code with AI
Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.rsi() and other built-in functions instantly.
Related Pine Script Functions
ta.stoch() - Stochastic Oscillator
Learn how to use ta.stoch() in Pine Script. Syntax, parameters, code examples for the Stochastic Oscillator.
ta.mfi() - Money Flow Index
Learn how to use ta.mfi() in Pine Script. Syntax, parameters, code examples for the volume-weighted RSI indicator.
ta.cci() - Commodity Channel Index
Learn how to use ta.cci() in Pine Script. Syntax, parameters, code examples for the CCI momentum indicator.
ta.cmo() - Chande Momentum Oscillator
Learn how to use ta.cmo() in Pine Script. Syntax, parameters, code examples for the Chande Momentum Oscillator.
ta.rma() - Relative Moving Average
Learn how to use ta.rma() in Pine Script. Syntax, parameters, code examples for Wilder's smoothing method used in RSI calculation.