// Fahodi Mean Reversion Strategy // Generated from stocks.basem.ai // TradingView Pine Script v5 //@version=5 strategy("Fahodi Mean Reversion", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=5) // Parameters rsiLength = input.int(14, "RSI Length", minval=2) rsiOversold = input.int(30, "RSI Oversold", minval=10, maxval=50) bbLength = input.int(20, "Bollinger Length", minval=5) bbMult = input.float(2.0, "Bollinger Multiplier", minval=0.5, step=0.1) smaFilter = input.int(200, "SMA Filter Length", minval=50) atrLength = input.int(14, "ATR Length") atrStopMult = input.float(2.0, "ATR Stop Multiplier", minval=0.5, step=0.5) // Indicators rsi = ta.rsi(close, rsiLength) [bbMiddle, bbUpper, bbLower] = ta.bb(close, bbLength, bbMult) sma200 = ta.sma(close, smaFilter) atr = ta.atr(atrLength) volAvg = ta.sma(volume, 20) // Entry: RSI oversold + at lower BB + above SMA200 longCondition = rsi < rsiOversold and close <= bbLower and close > sma200 // Strong entry: add volume confirmation strongEntry = longCondition and volume > volAvg * 1.5 // Exit: price reaches middle BB (mean reversion target) exitCondition = close >= bbMiddle // Strategy execution if strongEntry strategy.entry("MR Long", strategy.long) strategy.exit("MR Exit", "MR Long", stop=close - atr * atrStopMult, limit=bbMiddle) if exitCondition and strategy.position_size > 0 strategy.close("MR Long") // Plots plot(sma200, "SMA 200", color=color.gray, linewidth=2) plot(bbUpper, "BB Upper", color=color.blue, linewidth=1, style=plot.style_linebr) plot(bbMiddle, "BB Middle", color=color.blue, linewidth=1, style=plot.style_linebr) plot(bbLower, "BB Lower", color=color.blue, linewidth=1, style=plot.style_linebr) // Background color on signal bgcolor(longCondition ? color.new(color.green, 90) : na)