Candlestick Patterns
Candlestick pattern detection operates on raw OHLC candles rather than swing points. The detector identifies 19 single-, two-, and three-candle reversal formations, each with a required trend context.
Trend Detection
Constant: TREND_LOOKBACK = 5
| Condition | Trend |
|---|---|
close[now] − close[5 ago] > 0.2% × close[now] | uptrend |
close[now] − close[5 ago] < −0.2% × close[now] | downtrend |
| otherwise | neutral |
Single-Candle Patterns
| Pattern | Required Trend | Direction | Key Conditions |
|---|---|---|---|
| Hammer | downtrend | bullish | lower wick ≥ 2× body; upper wick ≤ 10% of body |
| Inverted Hammer | downtrend | bullish | upper wick ≥ 2× body; lower wick ≤ 10% of body |
| Shooting Star | uptrend | bearish | upper wick ≥ 2× body; lower wick ≤ 10% of body |
| Hanging Man | uptrend | bearish | lower wick ≥ 2× body; upper wick ≤ 10% of body |
| Doji | any | trend-dependent | body / candle range < 5%; bullish if downtrend, bearish otherwise |
Confidence formula (hammer/shooting star family):
confidence = (wickRatio − 2) / 3 × 0.7 + (1 − body/range) × 0.3
Where wickRatio = dominantWick / body. Clamped to [0, 1].
Two-Candle Patterns
c1 = prior candle, c2 = signal candle.
| Pattern | Required Trend | Direction | Key Conditions |
|---|---|---|---|
| Bullish Engulfing | downtrend | bullish | c1 bearish; c2 bullish; c2 body fully engulfs c1 body |
| Bearish Engulfing | uptrend | bearish | c1 bullish; c2 bearish; c2 body fully engulfs c1 body |
| Piercing Line | downtrend | bullish | c1 bearish; c2 bullish; c2 opens below c1 low, closes above c1 midpoint |
| Dark Cloud Cover | uptrend | bearish | c1 bullish; c2 bearish; c2 opens above c1 high, closes below c1 midpoint |
| Bullish Harami | downtrend | bullish | c1 bearish; c2 bullish; c2 body inside c1 body; c2 body ≤ 30% of c1 body |
| Bearish Harami | uptrend | bearish | c1 bullish; c2 bearish; c2 body inside c1 body; c2 body ≤ 30% of c1 body |
| Tweezer Top | uptrend | bearish | c1 bullish; c2 bearish; highs within 0.1% |
| Tweezer Bottom | downtrend | bullish | c1 bearish; c2 bullish; lows within 0.1% |
Three-Candle Patterns
c1 = first candle, c2 = middle/star candle, c3 = signal candle.
| Pattern | Direction | Key Conditions |
|---|---|---|
| Morning Star | bullish | c1 bearish (large); c2 small body (star gap down); c3 bullish, closes above c1 midpoint |
| Evening Star | bearish | c1 bullish (large); c2 small body (star gap up); c3 bearish, closes below c1 midpoint |
| Morning Doji Star | bullish | like Morning Star but c2 must be a doji (body / range < 5%) |
| Evening Doji Star | bearish | like Evening Star but c2 must be a doji |
| Three White Soldiers | bullish | 3 consecutive bullish candles; each opens inside prior body, closes higher; upper wick ≤ 20% of body |
| Three Black Crows | bearish | 3 consecutive bearish candles; each opens inside prior body, closes lower; lower wick ≤ 20% of body |
SL/TP
See TP Level Calculation for the full per-pattern breakdown.