The ta.rsi function is one of the most used in Pine Script because it calculates the Relative Strength Index (RSI) in a single line, without you having to implement Wilder’s formula by hand. In this straight-to-the-point guide you will see the correct syntax in Pine Script v6, the parameters, how to mark overbought and oversold zones, and ready-to-paste code for the TradingView editor. All in an honest tone: an indicator is a market-reading tool, not a crystal ball.
Tired of trading on manual clicks? See how to automate RSI signals in a real trading bot.
See the bot automation guide →Always test on a demo account before trading real money.
Syntax of the ta.rsi function
The signature is simple and takes only two arguments:
The return is a float value between 0 and 100. By convention, above 70 is considered overbought and below 30 oversold — but these thresholds are adjustable and do not mean an automatic entry signal.
ta. namespace. The old rsi() without the prefix (Pine v3/v4) is deprecated and throws an error in current versions.
Basic example: plotting the RSI
The code below creates an indicator with the 14-period RSI and the classic reference lines:
Detecting overbought and oversold
To generate threshold-crossing signals, combine ta.rsi with ta.crossover and ta.crossunder:
rsiValue > 70 fires the signal on every candle while the RSI stays above 70. ta.crossunder, on the other hand, fires a single time, at the exact moment of the cross — far more useful for alerts and automation.
Common mistakes when using ta.rsi
- Repainting from the wrong context: when pulling the RSI from another timeframe with
request.security, usebarmerge.lookahead_offso the script does not peek into the future. - Length too short: periods like 2 or 3 make the RSI extremely noisy; 14 is the default for a reason.
- Treating 70/30 as an order trigger: in a strong trend the RSI stays “glued” to the extreme zones for a long time. Overbought is not a guaranteed sell signal.
- Forgetting //@version=6: without declaring the version, the editor may interpret old syntax and break.
FAQ — ta.rsi in Pine Script
What is the default RSI period?
14 periods, following J. Welles Wilder’s original definition. It is the most used value and the recommended starting point.
Are ta.rsi and rsi() the same thing?
Functionally yes, but rsi() without the namespace belongs to older versions of Pine. In v6, always use ta.rsi.
Can I use a source other than close?
Yes. You can pass open, hl2, hlc3 or any series. The default and most common choice is close.
How do I use ta.rsi in a strategy for backtesting?
Calculate the RSI as usual and use the signals inside strategy.entry and strategy.exit, replacing indicator() with strategy() at the top of the script.
Does the RSI repaint?
On the chart’s own timeframe, no. The repainting risk appears when you combine it with data from another timeframe without configuring request.security correctly.
Disclaimer: binary options and leveraged trading are very high-risk products and most retail investors lose money. This content is educational and informational; it does not constitute an investment recommendation or a guarantee of results. Indicators such as the RSI are market-reading tools and do not predict the future. Always test on a demo account before trading real money.
