OPEN-SOURCE SCRIPT
Statistical Candle Patterns [QuantRegime]

## Overview
Most candle pattern indicators just label patterns on your chart. This one goes further — it **backtests every pattern against the actual chart history** and shows you the **real win rate** for each pattern on the specific instrument and timeframe you're trading.
A "Bullish Engulfing" might have a 68% win rate on BTC 4H but only 42% on EUR/USD 15m. This indicator tells you the difference. **Stop guessing which patterns work — measure them.**
## 12 Patterns Detected
| Pattern | Type | What It Signals |
|---------|------|----------------|
| **Bullish Engulfing** | Bullish | New candle fully engulfs previous bearish candle |
| **Bearish Engulfing** | Bearish | New candle fully engulfs previous bullish candle |
| **Hammer** | Bullish | Long lower wick, small body at top — rejection of lows |
| **Shooting Star** | Bearish | Long upper wick, small body at bottom — rejection of highs |
| **Doji** | Neutral | Tiny body — indecision, potential reversal |
| **Morning Star** | Bullish | 3-bar reversal: down → indecision → up |
| **Evening Star** | Bearish | 3-bar reversal: up → indecision → down |
| **Three White Soldiers** | Bullish | 3 consecutive strong green candles |
| **Three Black Crows** | Bearish | 3 consecutive strong red candles |
| **Inside Bar** | Neutral | Current bar fits inside previous bar — consolidation |
| **Bullish Marubozu** | Bullish | Strong green candle with almost no wicks |
| **Bearish Marubozu** | Bearish | Strong red candle with almost no wicks |
## How Win Rates Are Calculated
For each pattern occurrence in the lookback window:
1. Record the close price at the pattern
2. Look forward N bars (default: 5)
3. **Bullish patterns "win"** if the highest high in those N bars > pattern close
4. **Bearish patterns "win"** if the lowest low in those N bars < pattern close
5. Win Rate = wins / total occurrences × 100
This is a real backtest on the actual chart data — not some theoretical "textbook" win rate.
## The Statistics Dashboard
The bottom-right dashboard shows all 12 patterns with:
- **Win %** — Historical win rate on THIS symbol, THIS timeframe
- **Count** — How many times the pattern appeared
- **Type** — Bullish, Bearish, or Neutral
Win rates are color-coded:
- 🟢 60%+ = Strong edge
- 🟡 50-60% = Moderate
- 🔴 Below 50% = Pattern doesn't work here — skip it
## Smart Filtering
Labels only appear on the chart when:
- The pattern has appeared at least N times (configurable, default 3)
- The historical win rate exceeds your threshold (configurable, default 50%)
This means **you only see patterns that have actually worked** on this chart. Low-probability patterns are automatically hidden.
## Key Features
- **12 classic candle patterns** detected automatically
- **Real win rates** calculated from actual chart history — not theory
- **Smart filtering** hides unreliable patterns
- **Full statistics dashboard** with pattern-by-pattern breakdown
- **Customizable detection** — adjust body ratios, wick ratios, lookback windows
- **Toggle individual patterns** on/off
- **11 alert conditions** — one for each pattern type
- **Works on any market, any timeframe**
## Recommended Settings
| Style | Lookback | Outcome Bars | Min Win Rate |
|-------|----------|-------------|-------------|
| Scalping (1-5m) | 200-300 | 3 | 55% |
| Day Trading (15m-1H) | 500 | 5 | 50% |
| Swing (4H-Daily) | 500 | 5-10 | 50% |
| Position (Weekly) | 250 | 3-5 | 45% |
## Important Notes
- Win rates are calculated from historical data and **do not guarantee future results**
- Low occurrence counts (< 5) produce unreliable statistics — increase lookback or use a higher timeframe
- Some patterns (like Doji) are very common — consider raising the min body ratio to filter for higher-quality dojis
- The outcome window matters: 3 bars is aggressive, 10 bars gives more room
- Computing intensive on lower timeframes with high lookback — reduce lookback if the indicator loads slowly
## Disclaimer
This indicator is for educational and analytical purposes only. Past pattern win rates do not guarantee future performance. Always use proper risk management and never rely solely on candle patterns for trading decisions.
Most candle pattern indicators just label patterns on your chart. This one goes further — it **backtests every pattern against the actual chart history** and shows you the **real win rate** for each pattern on the specific instrument and timeframe you're trading.
A "Bullish Engulfing" might have a 68% win rate on BTC 4H but only 42% on EUR/USD 15m. This indicator tells you the difference. **Stop guessing which patterns work — measure them.**
## 12 Patterns Detected
| Pattern | Type | What It Signals |
|---------|------|----------------|
| **Bullish Engulfing** | Bullish | New candle fully engulfs previous bearish candle |
| **Bearish Engulfing** | Bearish | New candle fully engulfs previous bullish candle |
| **Hammer** | Bullish | Long lower wick, small body at top — rejection of lows |
| **Shooting Star** | Bearish | Long upper wick, small body at bottom — rejection of highs |
| **Doji** | Neutral | Tiny body — indecision, potential reversal |
| **Morning Star** | Bullish | 3-bar reversal: down → indecision → up |
| **Evening Star** | Bearish | 3-bar reversal: up → indecision → down |
| **Three White Soldiers** | Bullish | 3 consecutive strong green candles |
| **Three Black Crows** | Bearish | 3 consecutive strong red candles |
| **Inside Bar** | Neutral | Current bar fits inside previous bar — consolidation |
| **Bullish Marubozu** | Bullish | Strong green candle with almost no wicks |
| **Bearish Marubozu** | Bearish | Strong red candle with almost no wicks |
## How Win Rates Are Calculated
For each pattern occurrence in the lookback window:
1. Record the close price at the pattern
2. Look forward N bars (default: 5)
3. **Bullish patterns "win"** if the highest high in those N bars > pattern close
4. **Bearish patterns "win"** if the lowest low in those N bars < pattern close
5. Win Rate = wins / total occurrences × 100
This is a real backtest on the actual chart data — not some theoretical "textbook" win rate.
## The Statistics Dashboard
The bottom-right dashboard shows all 12 patterns with:
- **Win %** — Historical win rate on THIS symbol, THIS timeframe
- **Count** — How many times the pattern appeared
- **Type** — Bullish, Bearish, or Neutral
Win rates are color-coded:
- 🟢 60%+ = Strong edge
- 🟡 50-60% = Moderate
- 🔴 Below 50% = Pattern doesn't work here — skip it
## Smart Filtering
Labels only appear on the chart when:
- The pattern has appeared at least N times (configurable, default 3)
- The historical win rate exceeds your threshold (configurable, default 50%)
This means **you only see patterns that have actually worked** on this chart. Low-probability patterns are automatically hidden.
## Key Features
- **12 classic candle patterns** detected automatically
- **Real win rates** calculated from actual chart history — not theory
- **Smart filtering** hides unreliable patterns
- **Full statistics dashboard** with pattern-by-pattern breakdown
- **Customizable detection** — adjust body ratios, wick ratios, lookback windows
- **Toggle individual patterns** on/off
- **11 alert conditions** — one for each pattern type
- **Works on any market, any timeframe**
## Recommended Settings
| Style | Lookback | Outcome Bars | Min Win Rate |
|-------|----------|-------------|-------------|
| Scalping (1-5m) | 200-300 | 3 | 55% |
| Day Trading (15m-1H) | 500 | 5 | 50% |
| Swing (4H-Daily) | 500 | 5-10 | 50% |
| Position (Weekly) | 250 | 3-5 | 45% |
## Important Notes
- Win rates are calculated from historical data and **do not guarantee future results**
- Low occurrence counts (< 5) produce unreliable statistics — increase lookback or use a higher timeframe
- Some patterns (like Doji) are very common — consider raising the min body ratio to filter for higher-quality dojis
- The outcome window matters: 3 bars is aggressive, 10 bars gives more room
- Computing intensive on lower timeframes with high lookback — reduce lookback if the indicator loads slowly
## Disclaimer
This indicator is for educational and analytical purposes only. Past pattern win rates do not guarantee future performance. Always use proper risk management and never rely solely on candle patterns for trading decisions.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.