RSI Mean Reversion Strategy

Pine Script strategy by Chart GT · Published

Buys when RSI recovers from oversold, sells when it reaches overbought, with a stop loss.

Tags: strategy, mean-reversion, momentum

Source code

//@version=6
// @name RSI Mean Reversion Strategy
// @description Buys when RSI recovers from oversold, sells when it reaches overbought, with a stop loss.
// @tags strategy,mean-reversion,momentum
strategy("RSI Mean Reversion Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
length = input.int(14, "RSI length", minval=1)
oversold = input.float(30, "Oversold")
overbought = input.float(70, "Overbought")
stopPct = input.float(5, "Stop loss %", minval=0.1, step=0.1)
r = ta.rsi(close, length)
if ta.crossover(r, oversold)
    strategy.entry("Long", strategy.long)
if ta.crossover(r, overbought)
    strategy.close("Long")
if strategy.position_size > 0
    strategy.exit("Stop", "Long", stop=strategy.position_avg_price * (1 - stopPct / 100))

License: MPL-2.0

Open the chart to add it, or browse more community scripts.