OPEN-SOURCE SCRIPT
BB Mean Reversion Long + SL

This strategy exploits statistical price extremes using Bollinger Bands
on a mean reversion logic — when price closes below the lower band,
it's statistically outside 95% of normal price action.
That's the entry. The target is simple : get back to the mean.
━━━ LOGIC ━━━
- Entry → price closes below the lower band (crossunder)
- Take Profit → price returns to the SMA (middle band)
- Stop Loss → fixed % below entry price
━━━ SETTINGS ━━━
- SMA Period (N) → default 20
- Standard Deviations (K) → default 2.0
- Stop Loss % → default 1.5%
- Pyramiding → up to 3 simultaneous entries
━━━ BEST TIMEFRAME ━━━
Tested and works best between 45min and 2h.
Below 30min : too much noise.
Above 2h : price extremes often reflect real trend, not overreaction.
━━━ NOTES ━━━
→ Designed for mean-reverting assets with clear volatility cycles
→ Works particularly well on XAUUSD, indices ETFs
→ Avoid running during major news events (NFP, CPI, Fed)
→ Not recommended to hold positions over the weekend
→ qty is set to fixed lot — adjust to your broker's lot size
Tune N and K to your asset. Default settings are a starting point,
not a final answer. The edge is in the calibration.
on a mean reversion logic — when price closes below the lower band,
it's statistically outside 95% of normal price action.
That's the entry. The target is simple : get back to the mean.
━━━ LOGIC ━━━
- Entry → price closes below the lower band (crossunder)
- Take Profit → price returns to the SMA (middle band)
- Stop Loss → fixed % below entry price
━━━ SETTINGS ━━━
- SMA Period (N) → default 20
- Standard Deviations (K) → default 2.0
- Stop Loss % → default 1.5%
- Pyramiding → up to 3 simultaneous entries
━━━ BEST TIMEFRAME ━━━
Tested and works best between 45min and 2h.
Below 30min : too much noise.
Above 2h : price extremes often reflect real trend, not overreaction.
━━━ NOTES ━━━
→ Designed for mean-reverting assets with clear volatility cycles
→ Works particularly well on XAUUSD, indices ETFs
→ Avoid running during major news events (NFP, CPI, Fed)
→ Not recommended to hold positions over the weekend
→ qty is set to fixed lot — adjust to your broker's lot size
Tune N and K to your asset. Default settings are a starting point,
not a final answer. The edge is in the calibration.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.