The Relative Strength Index — J. Welles Wilder's momentum oscillator (1978).
RSI = 100 − 100 / (1 + RS)
Default period: 14. Scale: 0–100.
• RSI > 70 → overbought (price may pull back)
• RSI < 30 → oversold (price may bounce)
Divergence: Price makes new high but RSI doesn't → bearish divergence (momentum weakening)
Five-day RSI with Wilder’s smoothing (seeded here from the first change; the textbook seeds with a simple average, which only changes the first values). After the run-up it read 94.3 on day 5 — “overbought” — yet the price kept rising to 109 on day 7. On day 13, after four down days in five, it reached 29.9, below 30; by day 15 the close had climbed from 99 to 104.
The example data: 15 days, used in every indicator here
| Day | High | Low | Close | Volume |
|---|---|---|---|---|
| 1 | 101 | 99 | 100 | 50,000 |
| 2 | 103 | 100 | 102 | 62,000 |
| 3 | 103 | 100 | 101 | 48,000 |
| 4 | 105 | 101 | 104 | 70,000 |
| 5 | 108 | 104 | 107 | 85,000 |
| 6 | 108 | 105 | 106 | 60,000 |
| 7 | 110 | 106 | 109 | 90,000 |
| 8 | 110 | 107 | 108 | 72,000 |
| 9 | 108 | 104 | 105 | 80,000 |
| 10 | 105 | 102 | 103 | 66,000 |
| 11 | 105 | 102 | 104 | 55,000 |
| 12 | 104 | 101 | 102 | 75,000 |
| 13 | 102 | 98 | 99 | 95,000 |
| 14 | 102 | 99 | 101 | 64,000 |
| 15 | 105 | 101 | 104 | 71,000 |
- Overbought is not a sell signal in a trend: in a strong rise RSI can stay above 70 for weeks while the price keeps climbing.
- The 70 and 30 lines are convention, not calibration; the useful levels depend on the asset and the period.
- Divergences (a new price high without a new RSI high) look clear in hindsight; in real time they are frequent, and most do not lead to a reversal.
d = df['close'].diff() gain = d.clip(lower=0).ewm(alpha=1/5, adjust=False).mean() # Wilder smoothing loss = (-d.clip(upper=0)).ewm(alpha=1/5, adjust=False).mean() df['rsi5'] = 100 - 100 / (1 + gain / loss)
Assumes import numpy as np, import pandas as pd, and a DataFrame df with columns high, low, close and volume — the 15 days above.
- New Concepts in Technical Trading Systems, J. W. Wilder, Trend Research, 1978
- C.-H. Park & S. H. Irwin, “What Do We Know About the Profitability of Technical Analysis?”, Journal of Economic Surveys 21(4), 2007 — a review of the evidence across studies
Last reviewed October 2026 · How this site checks its content · Report a mistake
1. RSI stays above 70 during a strong uptrend. What does that tell you?
Show answer
B. Fading every reading above 70 in a trend repeatedly sells too early.
2. What is RSI built from?
Show answer
C. RSI = 100 − 100 / (1 + average gain / average loss), with Wilder’s smoothing in the classic version.
3. How does a 5-period RSI differ from a 14-period one?
Show answer
C. A shorter window averages fewer moves, so the ratio swings more. Fixed thresholds mean different things at different lengths.
- Download OHLCV data and compute RSI using only historical closes.
- Define the trading rule before testing: threshold, hold period, stop, and transaction cost.
- Use walk-forward validation; tune thresholds on one period and test on the next.
- Compare against buy-and-hold and cash baselines.
- Report Sharpe, max drawdown, hit rate, turnover, and cost sensitivity.
- Tests of simple RSI rules give mixed results across markets and periods (Park & Irwin 2007); there is no reliable published figure for how often divergences lead to reversals
- In strong trends, RSI can stay above 70 for weeks. Treating every "overbought" as a sell signal loses money in trending markets
- Andrew Cardwell’s framework shifts the zones with the regime: roughly 40–80 in bull markets, 20–60 in bear markets
pip install yfinance pandas pandas-ta
import yfinance as yf
import pandas_ta as ta
df = yf.download('SPY', start='2018-01-01', auto_adjust=True)
df['RSI_14'] = ta.rsi(df['Close'], length=14)
df['signal'] = (df['RSI_14'] < 30).astype(int).shift(1).fillna(0)
df['strategy'] = df['signal'] * df['Close'].pct_change()
print(df[['Close', 'RSI_14', 'signal', 'strategy']].tail())- LLM EngineeringMulti-Head AttentionRunning multiple attention computations in parallel
- Technical IndicatorsMoney Flow IndexRSI with volume in it: overbought and oversold, weighted by how much money changed hands
- ML MathGRULSTM's streamlined sibling — two gates, one state vector
- The Toolkitpandas-ta & yfinanceTechnical indicators + market data in one-liners
- The ToolkitROC & AUC CurvesVisualising model performance across all thresholds