The RSI mean-reversion strategy uses the Relative Strength Index to identify when price has stretched far from its recent average and may be due to snap back toward it. Traders typically treat low RSI readings as a potential "oversold" condition and high readings as "overbought," then watch for a move back inside normal levels as their signal to act. This page explains how the approach works and how to read it; it is educational only and makes no claim about profitability — RSI describes past price behaviour, not future direction, and trading carries real risk of loss.
Mean reversion is the idea that prices tend to oscillate around an average rather than move in a straight line forever. The RSI (Relative Strength Index) is a momentum oscillator bounded between 0 and 100 that compares the size of recent up-moves to recent down-moves over a lookback window (commonly 14 bars). When RSI falls to a low extreme, it indicates recent selling pressure has been strong relative to buying; when it climbs to a high extreme, the reverse. A mean-reversion trader interprets these extremes as a sign that price has moved a long way from its recent norm and may revert — though there is no guarantee it will. Rather than acting at the extreme itself, many traders wait for RSI to cross back through a threshold (for example, rising back above 30, or falling back below 70) as confirmation that the stretch is unwinding. Exits are then defined by RSI returning toward the midpoint (around 50), by a fixed target, or by a stop. It is worth stressing that "oversold" does not mean "must go up" — a market in a strong trend can stay at an RSI extreme for a long time, which is the central weakness of this approach.
//@version=6
// Educational example only — not financial advice and not a recommendation.
// Illustrative parameters; results from any backtest are hypothetical (past != future).
strategy("RSI Mean-Reversion (Educational)", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=1)
// Inputs
rsiLen = input.int(14, "RSI Length", minval=1)
osLevel = input.int(30, "Oversold Level", minval=1, maxval=50)
obLevel = input.int(70, "Overbought Level", minval=50, maxval=99)
exitLvl = input.int(50, "Neutral Exit Level", minval=1, maxval=99)
trendLen = input.int(200, "Trend Filter MA Length", minval=1)
// Calculations (all use confirmed close values; strategy fills on the next bar by default)
rsi = ta.rsi(close, rsiLen)
trendMA = ta.sma(close, trendLen)
// Trend filter: fade pullbacks in the direction of the longer trend
uptrend = close > trendMA
downtrend = close < trendMA
// Entry signals: RSI crosses back inside from an extreme
longEntry = ta.crossover(rsi, osLevel) and uptrend
shortEntry = ta.crossunder(rsi, obLevel) and downtrend
// Exit signals: RSI reverts to neutral
longExit = ta.crossover(rsi, exitLvl)
shortExit = ta.crossunder(rsi, exitLvl)
if longEntry
strategy.entry("Long", strategy.long)
if shortEntry
strategy.entry("Short", strategy.short)
if longExit
strategy.close("Long")
if shortExit
strategy.close("Short")
// Plots for context
plot(rsi, "RSI", color=color.new(color.blue, 0))
hline(obLevel, "Overbought", color=color.new(color.red, 50))
hline(osLevel, "Oversold", color=color.new(color.green, 50))
hline(exitLvl, "Neutral", color=color.new(color.gray, 50))The conventional defaults are a 14-period RSI with 30/70 thresholds, but these are starting points, not magic numbers, and they are examples rather than recommendations. Shorter lengths react faster and fire more signals; tighter levels (e.g. 20/80) wait for more extreme stretches. The right settings depend on the market, timeframe, and your exit logic — and any setting that looks great on one history should be checked on data it wasn't tuned on.
No. Mean reversion assumes price oscillates around an average, which tends to describe range-bound or choppy markets better than strongly trending ones. In a persistent trend, RSI can stay overbought or oversold for a long time and fade signals can lead to repeated losses. Many traders add a trend filter (like the long-term moving average in the example) to only take signals that align with the broader direction. None of this guarantees any outcome — it is about defining conditions, not predicting them.
The common hidden faults are look-ahead bias (using information a bar couldn't have known yet), repainting (signals that change after the fact), and intent mismatches (the code doesn't do what you described in plain English). ForexCodes' Strategy Validator is built to catch exactly these — it turns a plain-English or AI-written strategy into validated Pine Script v6 and flags those issues before you trust a backtest. Try it free.
Educational & software only — not financial advice, not a recommendation to trade. Backtests are illustrative; past performance does not predict future results. Trading involves substantial risk of loss.