How it works
How RSI is calculated
The Relative Strength Index compares the size of recent gains with recent losses over a lookback, usually 14 bars:
- For each bar, gain = max(close - previous close, 0) and loss = max(previous close - close, 0).
- Average gain and average loss use Wilder's smoothing: the first value is a simple 14-bar average, then each new value is (previous average × 13 + current value) / 14.
- RS = average gain / average loss, and RSI = 100 - 100 / (1 + RS).
RSI runs from 0 to 100. Readings above 70 are called overbought and below 30 oversold, but those words describe momentum, not value.
What happened on real data
We ran RSI(14) on our free daily bars for BTC-USDT and ETH-USDT, 1 July to 31 October 2026, 123 bars each. The last BTC bar in the file:
| symbol | interval | timestamp | open | high | low | close | volume |
|---|---|---|---|---|---|---|---|
BTC-USDT |
1d | 2026-10-31T00:00:00Z | 77368.76 | 77796.01 | 77114.01 | 77582.02 | 6287.54041 |
Source: Binance. Columns quote_volume, vwap, trade_count and taker_buy_volume omitted here.
Over those four months BTC rose from 60,024 to 77,582. Its RSI never fell below 34.4, which it reached on 30 October. It stayed above 80 from 20 to 27 August. The classic rule (buy below 30, exit above 50) made zero trades on BTC. ETH came closest, with RSI at 30.1 on 30 October, still above the line, so zero trades there too.
Loosen the entry to RSI below 35 and you get one trade on each, both opened in the last days of the file. That is not a strategy result. It is a reminder that a mean-reversion rule needs enough history to contain several pullbacks, and four months of a trending market doesn't have them.
Code
The code
"""Example: Wilder RSI(14) and a simple long-only rule, next-open fills."""
import pandas as pd
df = pd.read_csv("btc-eth-daily-bars.csv", parse_dates=["timestamp"])
df = df[df["symbol"] == "BTC-USDT"].set_index("timestamp").sort_index()
delta = df["close"].diff()
gain = delta.clip(lower=0)
loss = -delta.clip(upper=0)
avg_gain = gain.ewm(alpha=1/14, min_periods=14, adjust=False).mean()
avg_loss = loss.ewm(alpha=1/14, min_periods=14, adjust=False).mean()
df["rsi"] = 100 - 100 / (1 + avg_gain / avg_loss)
entry, exit_ = 30, 50
pos, trades = 0, []
for i in range(len(df) - 1):
r, nxt = df["rsi"].iloc[i], df["open"].iloc[i + 1]
if pos == 0 and r < entry:
pos, px = 1, nxt
elif pos == 1 and r > exit_:
trades.append(nxt / px - 1)
pos = 0
print("min RSI:", round(df["rsi"].min(), 1), " trades:", len(trades))
The ewm call with alpha=1/14 gives Wilder's smoothing, though it seeds slightly differently from a strict 14-bar simple average, so early values can differ a little from a charting platform. After about 50 bars the two agree closely. Signals use the close; fills use the next day's open.
Watch out
Common mistakes
Testing on a short window. A few months can be one long trend, as above. Test on several years that include falling and sideways markets.
Using the same thresholds everywhere. A volatile altcoin and a utility stock have very different RSI ranges. Look at the distribution of RSI for each market before you pick levels.
Filling at the signal close. RSI uses the close, so you only know the signal after the bar ends. Fill on the next open.
Optimising thresholds on all your data. Try 25, 28, 30, 32 and 35 on the full history and pick the best, and you have fitted noise. Choose on one period, then test on a later one you didn't look at.
Ignoring the trend. RSI dips in an uptrend are often buying chances, and the same dips in a downtrend are often traps. Many traders only take oversold longs when price is above a long moving average.
Details
Get the data
Free daily bars to run this yourself. BTC-USDT and ETH-USDT, July to October 2026, plus SOL, XRP, BNB, DOGE and ADA in a second file.
- Download BTC and ETH daily bars
- Download altcoin daily bars
- Source: Binance
- For years of history: crypto historical data, available in early access. RSI and other indicators by API: technical indicators API.
FAQ
Frequently asked questions
Does an RSI strategy work?
It can in range-bound markets, but the simple 30/70 rule has a weak record on its own, especially in strong trends. Results depend heavily on the market, the period and costs. Always test across several market conditions.
What RSI settings are best for backtesting?
The standard is 14 periods with 30 and 70 thresholds. Shorter lookbacks like 2 to 5 produce many more signals and are popular for short-term mean reversion. Choose settings on one period and confirm them on another.
Why does my RSI differ from my charting platform?
Platforms seed Wilder's average differently and may use more history before your first bar. Values converge after a few dozen bars. Load extra history before your test window to avoid the difference.
How many trades do I need to trust a backtest?
There is no fixed number, but a handful of trades tells you almost nothing. Aim for dozens at least, across different market conditions, before reading anything into the win rate.
Keep reading