RSI Mean Reversion Strategy
Classic RSI mean reversion: enter long when RSI drops below the oversold threshold and then closes back above it (confirmation), exit when RSI reaches overbought. The confirmation bar (RSI crossing back from extreme) significantly reduces false entries versus entering at the extreme itself.
Pine Script v6 — Complete Strategy Code
//@version=6//@version=6
strategy("RSI Mean Reversion", overlay=true,
default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// ── Inputs ──
int rsiLen = input.int(defval=14, title="RSI Length", minval=1, group="RSI")
int osLevel = input.int(defval=30, title="Oversold", minval=1, maxval=49, group="RSI")
int obLevel = input.int(defval=70, title="Overbought", minval=51, maxval=99, group="RSI")
float slMult = input.float(defval=2.0, title="SL ATR Mult", minval=0.1, step=0.1, group="Risk")
// ── Calculations ──
float rsi = ta.rsi(close, rsiLen)
float atr = ta.atr(14)
bool longEntry = rsi[1] < osLevel and rsi > osLevel // RSI crossing back above OS
bool shortEntry = rsi[1] > obLevel and rsi < obLevel // RSI crossing back below OB
bool longExit = rsi > obLevel
bool shortExit = rsi < osLevel
// ── Visuals ──
plotshape(longEntry, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(shortEntry, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// ── Orders ──
if longEntry
strategy.entry("Long", strategy.long)
strategy.exit("XL-SL", from_entry="Long", stop=low - atr * slMult)
if shortEntry
strategy.entry("Short", strategy.short)
strategy.exit("XS-SL", from_entry="Short", stop=high + atr * slMult)
if longExit
strategy.close("Long", comment="RSI OB exit")
if shortExit
strategy.close("Short", comment="RSI OS exit")
// ── Alerts ──
alertcondition(longEntry, title="RSI Long Entry", message="RSI oversold reversal — {{ticker}}")
alertcondition(shortEntry, title="RSI Short Entry", message="RSI overbought reversal — {{ticker}}")Copy and paste into TradingView Pine Editor, or generate a custom variation with AI.
How it works
Strategy logic, step by step
- 1
RSI(14) is calculated on close.
- 2
Long entry: RSI was below 30 (oversold) last bar and is now above 30 (crossing back up).
- 3
Exit long: RSI crosses above 70 (overbought) — close the position.
- 4
Short entry: RSI was above 70 (overbought) last bar and is now below 70 (crossing back down).
- 5
Exit short: RSI crosses below 30 (oversold) — close the position.
- 6
ATR stop loss as safety net in case of extended moves against position.
Parameters
Configurable inputs
| Parameter | Default |
|---|---|
| RSI Length | 14 |
| Oversold | 30 |
| Overbought | 70 |
| SL ATR Mult | 2.0 |
Ask the TradePilot copilot to backtest this and sweep the inputs to find the best combination for your asset and timeframe.
FAQ
RSI Mean Reversion Strategy questions
Why wait for RSI to cross back rather than entering at the extreme?
Entering at RSI=30 means entering into a falling market. Waiting for RSI to cross back above 30 means the momentum has shifted — you have confirmation the reversal is starting, not just that price is low.
Does RSI mean reversion work on crypto?
It works better on less volatile assets (indices, stable pairs). On highly volatile crypto, RSI can stay extreme for a long time and the ATR stop will often be hit. Use the 4H or Daily timeframe rather than shorter ones.
More strategies
Other Pine Script strategies
EMA Crossover Strategy
Fast/slow EMA crossover with RSI filter — the most tested trend-following setup in retail trading.
Supertrend Strategy
ATR-based trend-following with dynamic support/resistance. Two parameters, clear signals, easy to optimize.
RSI Divergence Strategy
Enter on confirmed RSI divergence — price making new extremes while RSI fails to confirm.
Want a custom version of this strategy?
Describe your modifications in plain English — different indicators, different risk parameters, long-only, multi-timeframe filter — and TradePilot generates the full Pine Script v6 code in seconds.