RSI indicator: formula, 70/30 levels and how to test RSI rules
RSI compares recent gains with recent losses on a 0–100 scale. The 70/30 levels mark one-sided recent movement, not a coming reversal, and no RSI setting is best until it holds up after costs and on unseen data.
By Soren Huang · Published · updated · Editorial policy
Contents
What is the RSI indicator and how is it calculated?
The RSI (relative strength index) is a momentum indicator that compares the size of recent up moves with recent down moves and scales the result from 0 to 100. Its creator, J. Welles Wilder Jr., used 14 bars. Readings above 70 are called overbought and below 30 oversold, but in strong trends RSI can stay there for a long time.
The relative strength index is a momentum oscillator, which is an indicator that moves between fixed limits and measures how strongly and how consistently price has been moving. Think of it as a scoreboard for the last 14 rounds. If buyers won most of the points, the score is high. If sellers did, it is low. RSI works the same way on stocks, futures, currencies and any other bar series. It is also not the same as "relative strength" in the stock-picking sense, which compares one stock with an index. RSI only looks at one price series.
The formula has one line:
RSI = 100 − 100 ÷ (1 + RS)
Here RS is the average gain divided by the average loss over the chosen number of bars. "Average gain" is the typical size of the up closes. "Average loss" is the typical size of the down closes, written as a positive number. When gains are twice as large as losses, RS is 2 and RSI is about 67. When gains and losses are equal, RS is 1 and RSI is exactly 50.
Wilder's method builds the averages in four steps:
- For each bar, take the close minus the previous close. A positive change is a gain and the loss is zero. A negative change is a loss (written as a positive number) and the gain is zero.
- For the first value, average the first 14 gains and the first 14 losses. Bars with no gain count as zero gain, and the same applies to losses.
- For every later bar, the new average keeps 13/14 of the previous average and adds 1/14 of the new bar's gain or loss.
- Divide average gain by average loss to get RS, then apply the formula. If the average loss is zero, RSI is 100.
Step 3 is a slow exponential average. With 14 bars it reacts about as fast as a standard 27-bar exponential average, so Wilder's RSI is smoother than many traders expect. Some platforms offer a version based on simple averages instead, and it gives different values. Because each value carries some memory of earlier bars, load extra history before the period you test. Letting RSI(14) run for at least 100 bars before you read it is a common practice.
Hypothetical example
After 14 bars, the average gain is 6 points and the average loss is 3 points. RS = 6 ÷ 3 = 2, so RSI = 100 − 100 ÷ 3 = 66.7. The next bar closes 20 points higher. The new average gain is (6 × 13 + 20) ÷ 14 = 7.0. The new average loss is (3 × 13 + 0) ÷ 14 = 2.79. RS becomes 2.51 and RSI rises to 71.5. One strong bar pushed the reading above 70.
What do RSI 70 and 30 mean, and why do trends break them?
RSI above 70 or below 30 means recent movement was very one-sided, not that price has to reverse. Wilder suggested 70 and 30 as the overbought and oversold lines. Some traders use 80 and 20 to get fewer and more extreme signals. Short periods such as RSI(2) or RSI(5) reach the extremes far more often than RSI(14), so the same levels mean different things at different settings.
Trends break the classic reading for a simple reason. In a strong uptrend, gains outweigh losses in almost every 14-bar window. RSI then stays above 70 while price keeps climbing. A rule that sells every time RSI crosses 70 is a rule that shorts the trend. The same thing happens below 30 in a falling market. Many traders also see a "range shift": in uptrends, RSI pullbacks often stop around 40 to 50 instead of falling to 30. In downtrends, rallies often stall around 50 to 60.
| Market condition | What RSI above 70 usually reflects | How traders tend to use it |
|---|---|---|
| Sideways range | Price is near the top of the range | Fade the move back toward the middle |
| Strong uptrend | Momentum is strong and can stay strong | Hold longs; wait for a pullback to buy |
| Strong downtrend | A short, sharp bounce | Look for the bounce to fail; do not read it as a new uptrend |
How do traders use RSI divergence and RSI as a trend filter?
Divergence and trend filters use RSI as a measure of momentum rather than as a reversal signal. Divergence is a situation where price makes a new high or low but RSI does not confirm it. A bearish divergence is a higher price high with a lower RSI high. A bullish divergence is a lower price low with a higher RSI low. Both say the push is losing strength. Neither says when the turn will come. Divergence can repeat two or three times while the trend continues, so traders usually wait for price to confirm, for example by breaking the last swing low.
Divergence is also hard to test, because "a swing high" needs an exact definition. You have to decide how many bars on each side make a swing, how far apart the two highs can be, and which price event confirms the signal. If you cannot write the divergence as a rule, you cannot backtest it.
As a trend filter, RSI above 50 simply means gains outweighed losses in the window. A common pullback rule combines it with a trend line such as a 200-bar moving average. Only take longs when price is above the average, and buy when RSI(14) dips below 40 and then turns back up. This uses the range shift described above instead of fighting it.
| Use | Example rule | What you must define | Typical failure |
|---|---|---|---|
| Mean reversion | Buy when RSI crosses back above 30 | Exit, stop, holding time | Keeps buying in a falling trend |
| Divergence | Sell after a lower RSI high and a break of the swing low | Swing rules, distance, confirmation | Signals early, several times in a row |
| Trend filter | Longs only when RSI is above 50 | The entry signal it filters | Late at turning points |
| Trend pullback | Above a 200-bar average, buy RSI turning up from below 40 | Trend line, dip level, exit | Whipsaws when the trend flattens |
Is there a best RSI setting?
There is no single best RSI setting. The right period and levels depend on the market, the bar size, the session and how long you hold a trade. RSI(14) on 5-minute bars covers 70 minutes. On daily bars it covers about three weeks of trading. Those are different tools with the same name.
Sessions matter too. TAIEX futures (台指期) trade a day session from 08:45 to 13:45 Taiwan time and a night session from 15:00 to 05:00 the next morning. RSI(14) on day-only bars and on full-session bars gives different readings, because the night bars change the gains and losses inside the window. Test on the bars you will actually trade.
The "best RSI indicator" in a single backtest is usually partly luck. If you try many periods and levels and keep the top one, its result includes the noise that happened to suit it. Research on data snooping shows that the best of many tested rules looks better than it is, and that the search itself has to be accounted for (White, 2000; Sullivan, Timmermann and White, 1999). Overfitting is the habit of tuning a rule to the noise in past data until the backtest looks better than the rule really is (Bailey et al., 2014).
A better question is whether a setting sits on a plateau. If RSI periods from 10 to 18 and entry levels from 25 to 35 all give similar results, the idea is broad. If only RSI(13) with a level of 27 works, you have probably found noise.
How do you backtest an RSI strategy properly?
A fair RSI backtest uses exact rules, next-bar fills, realistic costs and data the rule never saw while you tuned it. Follow these steps in order:
- Write the rule exactly. Period, levels, the trigger (crossing below 30 or crossing back above 30), exit, stop and session. Small wording differences change the results.
- Signal on the close, fill on the next bar. RSI is only known when the bar closes, so a fill at that same close uses a price you could not get.
- Include commission and slippage from the first run. Slippage is the difference between the price the backtest assumes and the price you would actually get. Short RSI settings trade often with a small edge per trade, so costs matter most there. See trading costs in backtests and the average trade.
- Keep data aside. Out-of-sample data is history that was not used to choose the rules or parameters. Better still, use walk-forward analysis, which re-tunes on one window and tests on the next, again and again.
- Test the neighbours. Run nearby periods and levels to check for a plateau.
- Check long and short trades separately, and count trades. A result built on 20 trades says little.
- Look across regimes. The history should include trends, ranges, quiet periods and volatile periods.
Hypothetical example
An RSI(2) mean-reversion rule on an index future shows 300 in-sample trades with a gross average trade of $40. Commission and slippage cost $25 per round trip, so the net average is $15. On the out-of-sample period the rule takes 80 trades with a gross average of $22. After the same $25 cost, the net average is −$3. The in-sample edge was real enough to look good, but too small to survive costs on new data.
The number of variants grows fast. Ten periods, ten oversold levels and ten exit rules already make a thousand combinations, and walk-forward analysis tests each one in every window. Strategy generation turns an idea such as "buy when momentum recovers from oversold" into testable rules with parameter ranges and entry and exit conditions. In AlphaPrime (Valynox), backtesting evaluates those variants in batches with fees, slippage, next-bar execution and trading sessions included. Strategy validation then applies walk-forward analysis and your own thresholds to the candidates that survive.
What this means if you use AlphaPrime (Valynox): treat RSI periods and levels as a range to search, not a fixed answer. Put costs and sessions into the search from the start, and keep only rules that pass walk-forward validation on data they did not see.
Frequently asked questions
What is the best RSI setting for day trading?
No setting is best for every market. RSI(14) on 5-minute bars covers about 70 minutes, while shorter periods react faster and reach 70 or 30 more often. Test a range of periods on the exact bars and session you trade, include costs, and pick a setting whose neighbours give similar results.
What does RSI above 70 mean?
It means recent gains were much larger than recent losses over the lookback window. In a sideways market that often happens near the top of the range. In a strong uptrend RSI can stay above 70 for a long time, so it is not a sell signal on its own.
Does an RSI 14 strategy work on its own?
A rule like "buy below 30, sell above 70" is simple to test, but it tends to buy repeatedly in falling trends. Many traders add a trend filter, a defined exit and a stop. Whether any version works on your market can only be judged after costs and on out-of-sample data.
Is there a free RSI indicator?
Yes. RSI is built into almost every charting and trading platform at no extra cost. Check whether your platform uses Wilder's smoothing or a simple average, because the two give different values for the same period.
What is the difference between RSI and the relative strength of a stock?
RSI measures the momentum of one price series on a 0 to 100 scale. Relative strength in stock picking compares one stock's performance with an index or another stock. The names are similar, but the calculations and uses are different.
References
- Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.
- Sullivan, R., Timmermann, A., & White, H. (1999). Data-Snooping, Technical Trading Rule Performance, and the Bootstrap. The Journal of Finance, 54(5), 1647–1691.
- White, H. (2000). A Reality Check for Data Snooping. Econometrica, 68(5), 1097–1126.
What AlphaPrime does here
AlphaPrime's strategy generation turns trading ideas into rules with parameter ranges, backtesting evaluates them in batches with costs and sessions included, and strategy validation checks them with walk-forward analysis and custom thresholds.

