RSI trading strategy (rules, code and the trend trap)
The Relative Strength Index is the most-used oscillator in trading and the easiest to misuse. It measures the speed of recent gains versus losses on a 0–100 scale, flagging when a market is stretched. The textbook play is to buy below 30 (oversold) and sell above 70 (overbought) — and in a ranging market it works beautifully. In a trend, it's a money-shredder. This guide gives the 14-period rules, the code, divergence, and the trap that catches every RSI beginner.
What RSI measures
RSI compares the average size of recent up-closes to recent down-closes over a lookback (classically 14 bars) and maps it to 0–100. High values mean gains have dominated (possibly overbought); low values mean losses have dominated (possibly oversold). It's a momentum oscillator — it tells you how stretched price is, not which direction it will go next.
The classic overbought/oversold rules
- Buy when RSI drops below 30 and turns back up (oversold).
- Sell/exit when RSI rises above 70 and turns back down (overbought).
- Trend variant — in strong uptrends, RSI rarely hits 30; some traders shift the band to 40/80 to stay aligned with the trend.
The code
python · rsi.pydef rsi(closes, n=14):
deltas = [closes[i]-closes[i-1] for i in range(1,len(closes))]
gains = sum(d for d in deltas[-n:] if d>0)/n
losses = -sum(d for d in deltas[-n:] if d<0)/n or 1e-9
rs = gains/losses
return 100 - 100/(1+rs)
r = rsi(closes)
if r < 30: signal = 'buy' # oversold
elif r > 70: signal = 'sell' # overbought
RSI divergence
The strongest RSI signal isn't the level — it's the divergence. When price prints a higher high but RSI prints a lower high, buying pressure is fading even as price rises. Bullish divergence is the mirror. Like all divergence, it's a warning that a move is tiring, not a precise entry; combine it with a trigger such as a break of a short-term swing.
The trend trap that ruins RSI beginners
In a powerful uptrend RSI can sit above 70 for a very long time while price keeps climbing — selling every “overbought” reading bleeds you out shorting strength. RSI mean-reversion only works in ranges. Gate it behind a trend filter, exactly as in the broader mean reversion strategy, and never short a strong trend just because an oscillator is high.
Sizing and risk
Because the loser in a trend can be large, RSI lives on stops. Use a hard stop beyond the recent extreme, size from it with the position calculator, and validate the 30/70 thresholds out-of-sample — they're the most over-fit numbers in retail trading. Compare RSI reversion against MACD momentum on the same market in the backtester to feel the regime difference.
Frequently asked questions
What is the RSI trading strategy?
The RSI (Relative Strength Index) strategy uses a 0–100 momentum oscillator to spot stretched markets: buy when RSI falls below 30 (oversold) and turns up, sell when it rises above 70 (overbought) and turns down. It is a mean-reversion strategy best suited to ranging markets.
What does RSI 30 and 70 mean?
30 is the classic oversold threshold and 70 the overbought threshold. RSI below 30 means recent losses have dominated and a bounce may be due; above 70 means recent gains have dominated. They are conventions, not guarantees — price can stay beyond them in trends.
What is RSI divergence?
RSI divergence is when price makes a new high or low but RSI does not, signalling that momentum is fading beneath the move. Bearish divergence (higher price high, lower RSI high) warns of a possible top; it is an early warning, not a precise entry trigger.
Why does RSI fail in a trend?
In a strong trend RSI can remain overbought above 70 (or oversold below 30) for a long time while price keeps moving, so fading every reading loses badly. RSI mean reversion works in ranges and needs a trend filter to avoid fighting sustained moves.