// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 16 — Bollinger mean-reversion with RSI confirm
// Purpose: parity test for combined ta.bb() boundary breach + ta.rsi() OB/OS
// confirmation entry.
//
//@version=6
strategy("Mean Reversion Bollinger", overlay=true, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)
// === Inputs ===
bbLen = input.int(20, "BB Length", minval=5)
bbMult = input.float(2.0, "BB Multiplier", step=0.1)
rsiLen = input.int(14, "RSI Length", minval=1)
rsiOB = input.int(70, "RSI Overbought")
rsiOS = input.int(30, "RSI Oversold")
// === Indicators ===
[bbMid, bbUpper, bbLower] = ta.bb(close, bbLen, bbMult)
rsiVal = ta.rsi(close, rsiLen)
// === Mean reversion: price at extremes + RSI confirmation ===
longCond = close < bbLower and rsiVal < rsiOS
shortCond = close > bbUpper and rsiVal > rsiOB
// === Strategy ===
if longCond
strategy.entry("Long", strategy.long)
if shortCond
strategy.entry("Short", strategy.short)
// === Exit at midline ===
if strategy.position_size > 0 and close > bbMid
strategy.close("Long")
if strategy.position_size < 0 and close < bbMid
strategy.close("Short")
plot(bbUpper, "Upper", color=color.red)
plot(bbMid, "Mid", color=color.gray)
plot(bbLower, "Lower", color=color.green)