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

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.