OPEN-SOURCE SCRIPT
CM - Bollinger Bands Mean Reversion [CriptoMatiko]

This indicator tracks **Bollinger Bands mean reversion signals**, replicating the entry and exit logic of a Python backtester that evaluated 81 long + 81 short parameter combinations on ETH/USDT 4H (Bybit Futures Linear, Mar 2025 – Aug 2026).
**The central finding:** the stop loss matters more than the band parameters.
| Setup | Direction | SL | Trades | Win Rate | Return |
|---|---|---|---|---|---|
| Standard (what tutorials teach) | Long | 2% | 110 | 38% | **-22.8%** |
| Optimized (indicator default) | Long | 1% | 110 | 38.2% | **+16.0%** |
| Buy & Hold ETH (same period) | — | — | — | — | -1.2% |
Same indicator. Same band parameters (20, 2.0). Different stop loss.
**Short side (optional):**
BB(20,2) shorts returned -17.4% — avoid with these settings. The optimizer found that shorts require different parameters: BB(10, 2.5) SL=1% TP=3R → +8.9% (Sharpe 7.81, 23 trades). Enable via the "Allow Short" input and adjust the parameters accordingly.
---
**Signal logic:**
- Long signal: bar closes **below** the lower Bollinger Band (no open position)
- Short signal: bar closes **above** the upper Bollinger Band (no open position)
- Entry: executed at the **next bar's open** (no lookahead)
**Exit logic — three mechanisms:**
1. **SL**: price hits SL% below (long) or above (short) the entry price
2. **TP**: price hits TP_ratio × risk from entry
3. **BB_UP / BB_DN**: bar closes beyond the opposite band (mean reversion complete)
**Default parameters (best Sharpe from 81-config long optimization):**
- BB Period: 20 | Std Deviation: 2.0 | Stop Loss: 1.0% | TP Ratio: 2.0R
**What makes this different from other BB indicators:**
- Parameters derived from a grid search (3 periods × 3 std devs × 3 SL% × 3 TP ratios × long/short/both)
- Simulated position tracking: entry marks appear on the next bar's open, matching backtester logic
- Three exit mechanisms with distinct markers (SL ✕ / TP ✓ / BB reversion ▽)
- SL and TP levels displayed as live lines during open position
- Short side included but with honest disclosure: BB(20,2) shorts underperform
- Uses ddof=1 standard deviation (biased=false) to match Python pandas behavior exactly
**Note:** This is an indicator with simulated position tracking, not a strategy. It shows signals and approximate trade timing for visual reference. For exact backtesting and the full optimizer: see GitHub link below.
**Tested on:** ETH/USDT 4H, Bybit Futures Linear. Validate on your own pair before using with real capital. Past performance does not guarantee future results.
**The central finding:** the stop loss matters more than the band parameters.
| Setup | Direction | SL | Trades | Win Rate | Return |
|---|---|---|---|---|---|
| Standard (what tutorials teach) | Long | 2% | 110 | 38% | **-22.8%** |
| Optimized (indicator default) | Long | 1% | 110 | 38.2% | **+16.0%** |
| Buy & Hold ETH (same period) | — | — | — | — | -1.2% |
Same indicator. Same band parameters (20, 2.0). Different stop loss.
**Short side (optional):**
BB(20,2) shorts returned -17.4% — avoid with these settings. The optimizer found that shorts require different parameters: BB(10, 2.5) SL=1% TP=3R → +8.9% (Sharpe 7.81, 23 trades). Enable via the "Allow Short" input and adjust the parameters accordingly.
---
**Signal logic:**
- Long signal: bar closes **below** the lower Bollinger Band (no open position)
- Short signal: bar closes **above** the upper Bollinger Band (no open position)
- Entry: executed at the **next bar's open** (no lookahead)
**Exit logic — three mechanisms:**
1. **SL**: price hits SL% below (long) or above (short) the entry price
2. **TP**: price hits TP_ratio × risk from entry
3. **BB_UP / BB_DN**: bar closes beyond the opposite band (mean reversion complete)
**Default parameters (best Sharpe from 81-config long optimization):**
- BB Period: 20 | Std Deviation: 2.0 | Stop Loss: 1.0% | TP Ratio: 2.0R
**What makes this different from other BB indicators:**
- Parameters derived from a grid search (3 periods × 3 std devs × 3 SL% × 3 TP ratios × long/short/both)
- Simulated position tracking: entry marks appear on the next bar's open, matching backtester logic
- Three exit mechanisms with distinct markers (SL ✕ / TP ✓ / BB reversion ▽)
- SL and TP levels displayed as live lines during open position
- Short side included but with honest disclosure: BB(20,2) shorts underperform
- Uses ddof=1 standard deviation (biased=false) to match Python pandas behavior exactly
**Note:** This is an indicator with simulated position tracking, not a strategy. It shows signals and approximate trade timing for visual reference. For exact backtesting and the full optimizer: see GitHub link below.
**Tested on:** ETH/USDT 4H, Bybit Futures Linear. Validate on your own pair before using with real capital. Past performance does not guarantee future results.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.