Momentum OscillatorsPine Script v6

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

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

Arguments

ParameterTypeDescription
sourceseries int/floatPrice or value series (commonly close).
lengthsimple intLookback length for averaging gains and losses.

Returns

Relative Strength Index.

Remarks

na values in the source series are ignored.

Code Examples

Pine Script v6 Example
//@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

ta.rsi() returns the Relative Strength Index: a bounded oscillator (0–100) that compares average gains vs average losses over length bars, using Wilder-style smoothing via ta.rma() internally.

Classic defaults treat roughly above 70 as overbought and below 30 as oversold. These are conventions, not guarantees; adjust thresholds to the market and timeframe.

Compare price swings with RSI swings: bullish divergence often appears when price makes a lower low while RSI makes a higher low; bearish divergence when price makes a higher high while RSI makes a lower high. Confirm with structure and risk management.

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.