← Back to Library
Momentum

RSI (Relative Strength Index)

RSI is a momentum oscillator that measures the speed and change of price movements. It operates between 0 and 100. This Pine Script V6 version calculates RSI based on closing prices and highlights overbought/oversold levels.

Pine Script V6
//@version=6
indicator('RSI', overlay=false)
len = input.int(14, 'Length')
src = input.source(close, 'Source')
up = ta.rma(math.max(ta.change(src), 0), len)
down = ta.rma(-math.min(ta.change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, 'RSI', color=color.purple)
hline(70, 'Overbought', color=color.red)
hline(30, 'Oversold', color=color.green)