RSI Strategy Backtest: Testing Overbought and Oversold on Indian Stocks
The RSI is the go-to indicator for spotting when a market has run too far, too fast. Used as a mean-reversion signal, it is simple to code and simple to backtest — but easy to misuse. Here is how RSI works, a basic strategy, and how to test it honestly on Indian stocks and indices.
What is the RSI?
The Relative Strength Index (RSI) is a momentum oscillator that moves between 0 and 100. It measures how strong recent gains are relative to recent losses over a lookback period (commonly 14). The traditional reading:
- Above 70 — the market is “overbought” (may be due for a pullback).
- Below 30 — the market is “oversold” (may be due for a bounce).
A simple RSI mean-reversion strategy
The classic rules buy weakness and sell strength:
- Buy when RSI falls below 30 (oversold).
- Exit when RSI recovers back above a middle level such as 55.
A runnable example
Here it is on a 15-minute chart, buying oversold dips and exiting on recovery:
EquitySymbol stock = NSE:EQ:"RELIANCE";
float[] rsi;
onTick {
INDICATOR_RSI(rsi, stock, M15, 14, 1);
// oversold -> buy
if (rsi[0] < 30) {
OrderSend(stock, BUY, 1, 0, 0, 0, INTRADAY, DAY, "rsi oversold");
}
// recovered -> exit
if (rsi[0] > 55) {
OrderCloseBySymbol(stock, INTRADAY, DAY, "rsi exit");
}
}The indicator fills the rsi array; rsi[0] is the latest value. See the indicators reference for the full RSI signature.
How to backtest it
- Test across many stocks and indices, not just one — an RSI edge that works on one symbol may vanish on another.
- Try different exit levels (50, 55, 60) but avoid tuning until it looks perfect.
- Validate on out-of-sample data.
- Include brokerage, taxes and slippage — mean-reversion trades are frequent, so costs add up.
The big pitfall: RSI in a strong trend
“Oversold” is not a buy signal in a downtrend — a falling market can stay oversold for a long time while it keeps falling. Naive RSI mean-reversion gets run over in strong trends. Most robust versions add a trend filter (only buy oversold when the longer-term trend is up) so you are buying dips within an uptrend, not catching a falling knife.
Variations worth testing
- Trend-filtered RSI — only take longs when price is above a long moving average.
- RSI + support — require the oversold reading near a known level.
- Different periods — a shorter RSI is twitchier; a longer one is smoother.
Try it
Build the RSI strategy in the SutraLipi platform, backtest it across a basket of stocks, then add a trend filter and compare. For a trend-following contrast, see the Supertrend strategy.
Try it on SutraLipi — free
Build, backtest and paper-trade the ideas in this guide without writing code.
Get Started FreeThis article is for education only and is not investment advice. Trading and investing in securities and derivatives carry risk of loss; past performance and backtested results do not guarantee future returns. Please read our Risk Disclosure Statement and consult a SEBI-registered adviser before trading.
