What is the RSI? Relative strength index formula and example
On this page
Key takeaways
- RSI, the relative strength index, compares the size of recent up days with the size of recent down days. When gains have dominated it reads high, when losses have dominated it reads low, and an even balance sits at fifty.
- Wilder's levels are 70 for overbought and 30 for oversold, on a 14-day lookback. They are conventions, not measured properties of any market.
- On an asset that rose over most of the years tested, the RSI tends to sit above fifty and only occasionally falls below thirty, so a rule that waits for an oversold reading is invested only a small part of the time.
- The same RSI supports opposite trades: buying oversold readings bets on a rebound, holding while the RSI is above fifty bets that strength continues. Which bet held up depends on the asset and the era.
- MarketHeist turns the RSI into a position with one rule at a time; the classic buy-below-30, sell-above-70 band needs separate entry and exit triggers, and it has its own robustness test.
Definition
The relative strength index (RSI) is a momentum oscillator, introduced by J. Welles Wilder in 1978, that compares the average size of recent up closes with the average size of recent down closes and scales the result from 0 to 100. Wilder used a 14-period lookback and called readings above 70 overbought and below 30 oversold.
Also known as: RSI, relative strength index, RSI 14, RSI 30/70, overbought and oversold, Wilder RSI, RSI(2), relative strength indicator.
How it works
Start with the change in the closing price from one day to the next. Split each change into a gain, the change if positive, and a loss, its size if negative. Average the gains and the losses over the lookback with Wilder's smoothing, an exponential average that gives each new day a weight of one over the period, one fourteenth for the standard RSI. Divide the average gain by the average loss to get the relative strength, RS, and rescale it to run from 0 to 100: the RSI is 100 minus 100 divided by one plus RS.
The scale is easy to read. If the period's up days and down days were the same size, RS is one and the RSI is fifty. If almost all the movement was upward, the RSI approaches 100; if almost all of it was downward, it approaches 0. Wilder treated readings above 70 as overbought, a rise that had run ahead of itself, and below 30 as oversold, and he also watched for divergences, where the price makes a new high that the RSI does not confirm.
The RSI is like a scoreboard of the last few weeks' rounds: it says who has been winning lately and by how much, not who wins the next round.
In practice the levels behave differently from their names. In a strong uptrend the RSI can stay above 70 for weeks while the price keeps rising, and in a crash it can sit below 30 while the price keeps falling. That is why the same indicator is used both ways: as a dip-buying signal, buying when it is oversold, and as a momentum filter, holding while it is above fifty. Short lookbacks, such as two days, make it jump between extremes almost daily and were popularised for short-term dip buying.
MarketHeist computes the RSI from daily closing prices adjusted for dividends and splits, and a single position rule compares it with one level. The classic band rule, buy below 30 and hold until above 70, has a memory between the two levels, so it needs the backtester's advanced mode with an entry trigger and an exit trigger; that is the rule MarketHeist's RSI robustness page tests.
Formula
- Pₜ
- adjusted closing price on day t
- Δₜ
- change in the close from the previous day, in price units
- Gₜ, Lₜ
- the day's gain and the size of the day's loss (one of them is 0)
- Ḡₜ, L̄ₜ
- the smoothed average gain and loss (see below)
- Ḡₜ / L̄ₜ
- RS, the relative strength
When the average loss is exactly 0, the RSI is 100.
- n
- the RSI period: 14 by default
- α
- the weight on the newest day: one over the period
L̄ₜ is computed the same way from the losses. Wilder seeded his running average with a simple average of the first n changes and then updated it with weight 1/n; MarketHeist uses the normalised exponential form above (pandas ewm with alpha = 1/n), which agrees with Wilder's once enough history has passed. The first n changes produce no value.
Worked example
SPY's daily bars from Oct 2006 to Sep 2026, about 20 years, with the 14-day RSI and three single rules, each acted on with the standard one-bar delay, no trading costs and no interest on cash.
Over the window SPY's 14-day RSI had a median of 57.00, and on four days in five it sat between 39.75 and 69.71. The oversold line at 30 lies below that whole range: the RSI was under 30 on only 1.7% of days. Its latest reading was 48.79.
Held only while oversold, the rule was invested on 1.7% of days, in 42 trades that lasted 2.0 days on average. 90.5% of those trades ended with a gain. The rule grew 3.7% a year against 11.1% for holding SPY, with a worst decline of -11.5% against -55.2%.
Read the other way, as momentum, long while the RSI was above 50, the 14-day RSI kept the rule invested on 69.2% of days, with 270 round trips, and it grew 4.3% a year with a worst decline of -44.1%.
The 2-day RSI below 10, a short-term dip-buying rule, traded far more often than the 14-day version: 265 trades, 13.3 a year. They lasted 1.8 days on average, 78.1% of them ended with a gain, and the rule grew 7.1% a year.
None of these is the classic band rule, which buys when the RSI falls below 30 and holds until it rises above 70. That rule needs separate entry and exit triggers; the RSI 30/70 robustness page tests it on SPY, QQQ, TLT, GLD and EFA with trading costs and interest on cash, and checks nearby periods and levels.
Data through Sep 2026. Reproduce id 3782e1981cb1e902 (this guide, its lab setup and the data month).
Interactive lab
SPY's price with the days invested shaded, the RSI with the rule's line, and the results table for the oversold rule, the momentum reading and the 2-day RSI against buy-and-hold. Change the period, the level, the direction, the delay, the cost or the fund.
| Measure | Base | Momentum: RSI(14) above 50 | Dip-buying: RSI(2) below 10 | Buy and hold |
|---|---|---|---|---|
| CAGR | 3.7% | 4.3% | 7.1% | 11.1% |
| Volatility (annualized) | 6.8% | 11.0% | 9.3% | 19.4% |
| Maximum drawdown | -11.5% | -44.1% | -15.5% | -55.2% |
| Sharpe ratio | 0.57 | 0.44 | 0.79 | 0.64 |
| Sortino ratio | 1.29 | 0.60 | 1.46 | n/a |
| Growth of $10,000 | $20,607 | $23,157 | $39,526 | $82,292 |
| Time in the market | 1.7% | 69.2% | 9.5% | 100.0% |
| Round trips | 42 | 270 | 265 | n/a |
| Round trips per year | 2.1 | 13.5 | 13.3 | n/a |
| Win rate | 90.5% | 30.7% | 78.1% | n/a |
| Average win | 2.1% | 4.0% | 1.1% | n/a |
| Average loss | -1.7% | -1.2% | -1.4% | n/a |
| Payoff ratio | 1.29 | 3.21 | 0.75 | n/a |
| Average days held | 2.0 | 12.9 | 1.8 | n/a |
| Expectancy per trade | 1.8% | 0.4% | 0.5% | n/a |
| Profit factor, per day | 2.45 | 1.10 | 1.70 | 1.13 |
| Profit factor, per trade | 12.23 | 1.43 | 2.69 | n/a |
| Indicator, last day | 48.789 | 48.789 | 13.902 | n/a |
| Indicator, 10th / 50th / 90th percentile | 39.753 / 56.997 / 69.706 | 39.753 / 56.997 / 69.706 | 10.439 / 63.38 / 95.153 | n/a |
| Days the rule alone is long | 1.7% | 69.1% | 9.5% | n/a |
S&P 500, Oct 2006 to Sep 2026, 5030 trading days. Every setup is measured over the same days, with the indicator warmed up on earlier ones; cash earns 0. Base: RSI (period 14); long while the RSI is below 30; execution delay 1; cost 0 bps one way. Momentum: RSI(14) above 50: RSI (period 14); long while the RSI is above 50; execution delay 1; cost 0 bps one way. Dip-buying: RSI(2) below 10: RSI (period 2); long while the RSI is below 10; execution delay 1; cost 0 bps one way.
| Buy and hold, same days | Value |
|---|---|
| Largest one-day gain | 14.5% on 13 Oct 2008 |
| Largest one-day loss | -10.9% on 16 Mar 2020 |
| CAGR without the 10 largest gains | 6.6% |
| CAGR without the 30 largest gains | 1.8% |
| CAGR without the 10 largest losses | 16.0% |
| CAGR without the 30 largest losses | 22.1% |
The days replaced by 0 are the largest daily gains (or losses) of the window.
How MarketHeist computes it
Every choice an implementation has to make, as the code makes it today. The page is checked against the code each time it is built.
| Choice | How it is computed | In the code |
|---|---|---|
| Data | Daily bars (open, high, low, close, volume) of the fund as the MarketHeist data service serves them to the backtester: prices adjusted for splits and dividends, so a dividend counts as reinvested. They come from a snapshot taken each month and cut at the data month of this page, and are not rounded. The fund's own history, not an extension: a fund younger than the window is measured over the years it has. | |
| Window | The worked example and the lab measure the last 20 years of trading days, Oct 2006 to Sep 2026 (5030 days), ending at the data month of this page. Every setup, and buy and hold, is measured over exactly these days; an indicator is warmed up on the days before them, so changing a setting never moves the window, and a setting that needs more history than exists before the window is refused rather than measured over fewer days. | |
| Backtest | The backtester's own engine, in the order it runs it: the indicator, the position rule (or entry and exit triggers) and the optional regime filter produce a position for every day of the fund's whole history; the position is then shifted forward by the execution delay and applied to each day's return over the window. Cash earns 0, there is no leverage, and a one-way cost in basis points is charged on the size of every change of position. Round trips are the closed entries of the trade log (a trade still open on the last day is not counted); the win rate is the share of them with a gain; the payoff ratio is the average win over the size of the average loss; expectancy is the average return per trade; the per-trade profit factor is the sum of the winning trades' returns over the size of the sum of the losing ones, while the per-day profit factor sums days. | |
| Years and volatility | A year is 252 trading days, the engine's convention: trades per year is round trips over days divided by 252, the CAGR is the growth multiple to the power 252 over the days, and volatility is the sample standard deviation of the daily returns times the square root of 252. | |
| Indicator statistics | The indicator's main output over the window: its last value, its 10th, 50th and 90th percentile (linear interpolation between ranks), and the share of days the rule alone says long, before the delay and any regime filter. Every output of the indicator is also summarized by its median and the share of days below 0. | |
| Buy and hold | The fund held every day of the window with dividends reinvested. The largest one-day gain and loss are the highest and lowest daily returns; the CAGR without the 10 or 30 largest gains (or losses) replaces those days' returns with 0 and recompounds. | |
| Price changes | Day-to-day differences of the adjusted close, in price units (not percentages), split into gains and losses. | diffpackages/shared/engine/utils.ts |
| Smoothing | Exponentially weighted means of gains and losses with α = 1 ÷ period, pandas adjust = True (weights normalised over the data so far, no simple-average seed), and no value until period changes have been seen. | ewmMeanAlphapackages/shared/engine/utils.ts |
| RSI | 100 − 100 ÷ (1 + average gain ÷ average loss); exactly 100 when the average loss is 0. | computepackages/shared/engine/indicators/rsi.ts |
| Defaults | Period 14 (range 2 to 200). The backtester's default rule is long while the RSI is above 30, which on most assets means invested almost all the time; set the level and direction explicitly for any test. | SPECpackages/shared/engine/indicators/rsi.ts |
| Band rules | A single rule compares the RSI with one level. Buy below one level and sell above another needs the advanced mode: an entry trigger (RSI below 30) and an exit trigger (RSI above 70) with the position held in between, as the RSI 30/70 robustness page runs it. | generateTriggeredPositionpackages/shared/engine/triggered_position.ts |
| Engine functions | The functions the portfolio app and the MarketHeist MCP tools run, called here on the same monthly returns. | computePositionpackages/shared/engine/run_basic.tsgeneratePositionpackages/shared/engine/positions.tsapplyRegimeFilterpackages/shared/engine/regime_filter.tsgenerateTriggeredPositionpackages/shared/engine/triggered_position.tsrunBacktestpackages/shared/engine/backtest.tsgetIndicatorpackages/shared/engine/indicators/registry.ts |
Relative strength index (RSI) compared with its neighbours
| Indicator | Measures | Inputs | Scale and usual levels |
|---|---|---|---|
| RSI | Average up closes against average down closes | Close | 0 to 100; 30 and 70 |
| Stochastic %K | Where the close sits in the recent high-low range | High, low, close | 0 to 100; 20 and 80 |
| Bollinger %B | Where the close sits between volatility bands | Close | 0 at the lower band, 1 at the upper; unbounded |
| CCI | Distance of the typical price from its average, in mean deviations | High, low, close | Unbounded; −100 and +100 |
Limitations
- Overbought and oversold are labels, not forecasts. An RSI can stay at an extreme for weeks in a strong trend or a crash.
- A single rule cannot express the band rule with separate entry and exit levels; the lab shows single-level rules and links to the band rule's own test.
- The example charges no trading costs. Short-period RSI rules trade often, and costs take a large share of their small average gains.
- Values differ slightly between platforms: the smoothing's start-up, adjusted versus unadjusted prices, and the period all change the number, especially early in a series.
- One fund over one window that rose for most of its length. An asset that trended down for years would show the oversold and momentum readings very differently.
Frequently asked questions
- What do RSI readings of 70 and 30 mean?
- They are Wilder's levels for overbought and oversold: above 70 the recent up moves have far outweighed the down moves, below 30 the reverse. They describe the recent past and are not signals that a turn is due; in strong trends the RSI can stay beyond them for a long time.
- Is 14 the right RSI period?
- It is Wilder's choice and the common default, not a value derived from any market. Shorter periods make the RSI jump between extremes and suit short-term trading; longer ones smooth it. Testing nearby periods, as the RSI robustness page does, shows whether a result depends on the exact choice.
- Is the RSI a momentum or a mean-reversion indicator?
- It measures momentum, the balance of recent gains and losses, and it is used both ways: buying oversold readings is a mean-reversion bet, holding while the RSI is high is a momentum bet. The two can give opposite positions on the same day.
- Why does MarketHeist's RSI differ slightly from my charting platform?
- Platforms differ in how they start the smoothing (a simple average of the first values or a weighted average from the first bar) and in whether prices are adjusted for dividends. MarketHeist uses dividend-adjusted closes and a normalised exponential average; after a few months of data the differences become very small.
- How do I backtest buying at RSI 30 and selling at RSI 70?
- In the backtester's advanced mode, with an entry trigger of RSI below 30 and an exit trigger of RSI above 70; the position is held between the two. The RSI 30/70 robustness page runs that rule on five funds.
References
- Wilder, J. W. (1978) New Concepts in Technical Trading Systems. Trend Research. Introduces the RSI, its 14-period default and the 70 and 30 levels.
- Connors, L. and Alvarez, C. (2008) Short Term Trading Strategies That Work. TradingMarkets. Short-period RSI rules for buying pullbacks.
- Murphy, J. J. (1999) Technical Analysis of the Financial Markets. New York Institute of Finance. Oscillators, overbought and oversold readings, divergences.
Try it on your own holdings
Open the RSI in the backtester →
Or ask an assistant connected to the MarketHeist MCP server (https://marketheist.io/mcp), which computes the same figures:
Using MarketHeist.io, backtest the 14-day RSI on SPY daily bars with execution delay 1 two ways, long only while RSI is below 30 and long while RSI is above 50, and compare time in the market, number of trades, CAGR and max drawdown with buy-and-hold.
Ask an AI assistant
The prompt opens in a new tab, already filled in. An assistant without the MarketHeist connector answers from its own knowledge, not from the figures on this page.
Historical simulation, not advice. Computed by the MarketHeist portfolio engine from monthly total returns, data through Sep 2026. Markdown version of this page: rsi.md.