Returns the relative strength index: average gains against average losses over length bars, scaled from 0 to 100.
ta.rsi takes the bar-to-bar change of source and splits it into gains and losses. Each side is smoothed with ta.rma over length bars, and the result is 100 - 100 / (1 + averageGain / averageLoss).
A reading near 100 means nearly all recent change was upward; near 0 means nearly all was downward. The first value appears on bar number length + 1, because the first bar has no change to measure.
Syntax
ta.rsi(source: series int/float, length: simple int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | Series whose changes are measured, usually close. |
| length | simple int | required | Smoothing length of the gain and loss averages. A whole number of 1 or more. |
Returns
series float: the RSI value between 0 and 100, or na for the first length bars.
Remarks
- Common reference levels are 70 and 30. They are conventions, not limits; RSI can stay above 70 for long stretches in a strong trend.
- Early values depend slightly on history length because
ta.rmais recursive.
Example
//@version=6
indicator("RSI")
len = input.int(14, "Length", minval = 1)
value = ta.rsi(close, len)
plot(value, "RSI", color = color.purple)
hline(70, "Overbought", color.red)
hline(30, "Oversold", color.green)See also
Runs on Sidechair