strategy · own pane · open source

RSI mean reversion strategy (RSI 14, 30 → 50)

RSI(14) mean reversion: buy when RSI is below 30, exit when it recovers above 50, with a 2%/6% bracket. Plain-English rules, code and a costed backtest. Deepwick Script runs a subset of Pine Script.

v1Updated 3 Oct 2026▲ 0 users
Running…
Loading chart…

What the RSI Mean Reversion strategy does

Classic RSI mean reversion long-only strategy. Buy when RSI drops into oversold territory, exit when it recovers to the midline.

  • Lower Oversold for fewer, higher-conviction signals; raise it for more trades.
  • Exit Level around 50 is the textbook mean; 55–60 holds trades longer.
  • Best in range-bound markets; combine with an ADX filter for trending ones.

Entry and exit rules

    Language reference: Deepwick Script.

    Default inputs

    InputDefaultMinMax
    RSI Length14250
    Oversold30545
    Exit Level503070
    Stop Loss %20.510
    Take Profit %6020

    How Deepwick fills this strategy

    • Market orders fill at the next bar's open.
    • Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
    • Gaps fill at the open.
    • Commission is charged on every fill, and slippage applies to market and stop fills, as set in strategy().

    More on how backtests work

    Source code

    Deepwick Script, a subset of Pine Script · read-only

    //@version=6
    strategy("RSI Mean Reversion", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
    len = input.int(14, "RSI Length", minval=2, maxval=50, step=1)
    oversold = input.int(30, "Oversold", minval=5, maxval=45, step=1)
    exitLevel = input.int(50, "Exit Level", minval=30, maxval=70, step=1)
    stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
    tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
    colorBg = input.color("color.purple", "Color  Bg")
    colorUp = input.color("color.green", "Color  Up")
    colorDown = input.color("color.red", "Color  Down")
    colorNeutral = input.color("color.gray", "Color  Neutral")
    r = ta.rsi(close, len)
    longSignal = strategy.position_size == 0 and r < oversold
    exitSignal = strategy.position_size > 0 and r > exitLevel
    if longSignal
        strategy.entry("Long", strategy.long)
    if strategy.position_size > 0
        strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
    if exitSignal
        strategy.close("Long", comment="RSI exit")
    hline(70, "Overbought", color=colorNeutral, linestyle=hline.style_dashed)
    hline(50, "Midline", color=colorNeutral, linestyle=hline.style_dotted)
    hline(30, "Oversold", color=colorNeutral, linestyle=hline.style_dashed)
    p_RSI = plot(r, "RSI", color=colorBg, linewidth=2)
    plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
    plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=colorDown, text="X")
    alertcondition(longSignal, "RSI long entry", "RSI dropped below oversold")
    alertcondition(exitSignal, "RSI exit", "RSI crossed above exit level")
    

    Run it in Deepwick

    1. Open a chart of any crypto pair or CFD.
    2. Click “Scripts” and add this strategy.
    3. Press Run and read the trades in the Strategy Tester.
    Start free

    FAQ

    Is this the RSI 2 strategy?

    No. It uses RSI 14 with 30/50 levels. For an RSI(2)-style test set RSI Length to 2 and lower the Oversold input, then rerun with the same costs.

    Why exit at 50 instead of 70?

    Mean reversion bets on a return to normal, not on a new trend. Exiting at the midline takes the snap-back and avoids waiting for an overbought reading that may never come.

    Does buying oversold RSI work in a downtrend?

    In strong downtrends RSI can stay below 30 for many bars, and the state-based entry keeps buying after each stop. Add a trend filter (e.g. close above a 200 EMA) and compare.

    Comments

    No comments yet.

    Sign in to comment.