Pine Script code for Relative Strength Index (RSI) Calculation

The Relative Strength Index (RSI) can be used for detecting overbought/oversold levels across different timeframes.

Suppose if we want to calculate 14-Period Relative Strength Index (RSI) for 5-minute timeframe, we need to use following pine script code.

ta.rsi(close, 14) is the built-in function of pine script to calculate 14-Period RSI value using the closing price.

request.security is a function in Pine Script used to retrieve data from different time frames or symbols.

syminfo.tickerid is for getting current symbol/ticker.

As of now we are using “5”, which gives data for 5 minute timeframe. if we want data for 1 minute we need to change it to “1”.

Finally we pass rsi_calc which gives calculated RSI value from the 5-minute timeframe.

Syntax of request.security is as follows