RSI Strategy for TradingView:
Working PineScript Code + Backtest

This strategy targets extreme oversold conditions in Bitcoin (RSI below 25) and enters long with a 5% trailing stop exit. Rather than using a fixed RSI exit level, the trailing stop dynamically protects profits during the recovery rally. Bitcoin's high volatility and strong mean-reverting behavior at extremes make this setup particularly effective. The strategy produces few but high-quality trades with large average gains per winning trade.

RSIPineScriptBTCUSD

What is Relative Strength Index — Deep Oversold?

This strategy applies the Relative Strength Index with a more aggressive oversold threshold of 25 (instead of the standard 30) specifically tuned for Bitcoin's volatile price action. Bitcoin's tendency to produce sharp, deep corrections followed by powerful recoveries makes it an ideal candidate for deep oversold bounce strategies. The lower threshold filters out minor pullbacks and only catches extreme fear-driven sell-offs where the probability of a bounce is highest. Combined with a trailing stop exit, the strategy lets winning trades run while protecting against continued downside.

ParameterValue
deep Oversold25
oversold30
midline50

RSI Deep Oversold Bounce — Bitcoin: The Setup

Entry Rules

  • RSI(14) crosses below 25 (deep oversold territory)
  • Enter long on the next bar open
  • Only one position open at a time
  • Position size: 100% of equity per trade

Exit Rules

  • Trailing stop at 5% below the highest close since entry
  • The trailing stop only activates after entry — it does not move down
  • No fixed take-profit — let the trailing stop capture the recovery

Working PineScript Code

The script enters long when RSI(14) crosses below 25 — a deep oversold level tuned for Bitcoin. The trailing stop is implemented manually using two persistent variables (`var`): `trailHigh` tracks the highest close since entry, and `trailStop` is calculated as 95% of that high. When price drops below the trailing stop, the position is closed. The `nz()` function handles the initial bar where `trailHigh` has no prior value. The `display=display.pane` parameter on the RSI plot creates a separate indicator pane below the price chart.

javascript
//@version=5
strategy("RSI Oversold Bounce BTC", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// === INPUTS ===
rsiLength = input.int(14, "RSI Length", minval=1)
oversoldLevel = input.int(25, "Oversold Level", minval=5, maxval=40)
trailPct = input.float(5.0, "Trailing Stop %", minval=1.0, maxval=20.0, step=0.5)

// === CALCULATIONS ===
rsiValue = ta.rsi(close, rsiLength)

// === ENTRY CONDITIONS ===
longCondition = ta.crossunder(rsiValue, oversoldLevel)

// === TRAILING STOP LOGIC ===
var float trailHigh = na
var float trailStop = na

if strategy.position_size > 0
    trailHigh := math.max(nz(trailHigh, close), close)
    trailStop := trailHigh * (1 - trailPct / 100)
else
    trailHigh := na
    trailStop := na

// === STRATEGY EXECUTION ===
if longCondition and strategy.position_size == 0
    strategy.entry("RSI Bounce", strategy.long)

if strategy.position_size > 0 and close < trailStop
    strategy.close("RSI Bounce", comment="Trailing Stop")

// === PLOTTING ===
plotshape(longCondition and strategy.position_size == 0, title="Entry Signal", location=location.belowbar, style=shape.triangleup, color=color.green, size=size.normal)
plot(strategy.position_size > 0 ? trailStop : na, "Trailing Stop", color=color.red, linewidth=2, style=plot.style_linebr)

// RSI Panel
plot(rsiValue, "RSI", color=color.purple, display=display.pane)
hline(oversoldLevel, "Oversold", color=color.green, linestyle=hline.style_dashed, display=display.pane)
hline(50, "Midline", color=color.gray, linestyle=hline.style_dotted, display=display.pane)

Backtest Results: BTCUSD (1D, 2020-2025)

Total Return

+89.3%

Annualized

+13.7%

Win Rate

62%

Max Drawdown

-35.2%

Sharpe Ratio

0.71

Total Trades

22

Profit Factor

1.88

Past performance does not guarantee future results. Backtest results may not reflect actual trading conditions including slippage, commissions, and liquidity constraints.

Optimization Tips

1

Test different trailing stop percentages. 5% works for daily BTC, but in extreme volatility events (like March 2020), even a 5% trail can be hit during an intra-day flash crash before recovery. Consider 7-8% trailing stop for Bitcoin specifically.

2

Add a volume confirmation filter. Require the oversold bar to have volume above its 20-period average. Capitulation events with high volume are more likely to produce genuine reversals than low-volume drift into oversold territory.

3

Implement a time-based exit as a fallback. If the position hasn't hit the trailing stop within 30 bars, consider closing regardless. Some oversold bounces are weak and the position can stagnate, tying up capital.

4

Consider scaling in across multiple RSI levels. Enter 50% of the position at RSI < 25 and the remaining 50% at RSI < 20 (if it gets there). This improves the average entry price on deeper corrections.

5

Add a macro trend filter using the 200-day SMA. Only take oversold bounce trades when BTC is above the 200 SMA. This filters out signals during bear markets where oversold conditions can persist for weeks.

Common Mistakes with RSI on TradingView

Using this strategy during a confirmed bear market. In Bitcoin's 2022 bear market, RSI spent extended periods below 30 and even below 25. Each bounce was sold into, making the trailing stop ineffective as the overall trend was down.

Setting the trailing stop too tight for Bitcoin. A 2-3% trailing stop on daily BTC will get triggered by normal intra-day volatility. Bitcoin regularly moves 3-5% intra-day, so the 5% minimum is important to avoid premature exits.

Expecting frequent trades. With only 22 trades over 5 years (about 4 per year), this is a patient strategy. Resist the urge to lower the RSI threshold to generate more signals — the deep oversold level is what gives the strategy its edge.

Not accounting for crypto exchange differences. BTC prices and RSI values can differ across exchanges. Ensure you're backtesting on the same exchange data feed you'll trade on. TradingView's BTCUSD index aggregates multiple exchanges, which may not match your broker's feed.

Build This Strategy in 60 Seconds with SpendDock

Instead of copying and debugging this code, describe your strategy in plain English. SpendDock generates the PineScript code, backtests it against real market data, and lets you iterate until it is right.

Try SpendDock Free

RSI on Other Platforms