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

ConditionTrend
close[now] − close[5 ago] > 0.2% × close[now]uptrend
close[now] − close[5 ago] < −0.2% × close[now]downtrend
otherwiseneutral

Single-Candle Patterns

PatternRequired TrendDirectionKey Conditions
Hammerdowntrendbullishlower wick ≥ 2× body; upper wick ≤ 10% of body
Inverted Hammerdowntrendbullishupper wick ≥ 2× body; lower wick ≤ 10% of body
Shooting Staruptrendbearishupper wick ≥ 2× body; lower wick ≤ 10% of body
Hanging Manuptrendbearishlower wick ≥ 2× body; upper wick ≤ 10% of body
Dojianytrend-dependentbody / 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.

PatternRequired TrendDirectionKey Conditions
Bullish Engulfingdowntrendbullishc1 bearish; c2 bullish; c2 body fully engulfs c1 body
Bearish Engulfinguptrendbearishc1 bullish; c2 bearish; c2 body fully engulfs c1 body
Piercing Linedowntrendbullishc1 bearish; c2 bullish; c2 opens below c1 low, closes above c1 midpoint
Dark Cloud Coveruptrendbearishc1 bullish; c2 bearish; c2 opens above c1 high, closes below c1 midpoint
Bullish Haramidowntrendbullishc1 bearish; c2 bullish; c2 body inside c1 body; c2 body ≤ 30% of c1 body
Bearish Haramiuptrendbearishc1 bullish; c2 bearish; c2 body inside c1 body; c2 body ≤ 30% of c1 body
Tweezer Topuptrendbearishc1 bullish; c2 bearish; highs within 0.1%
Tweezer Bottomdowntrendbullishc1 bearish; c2 bullish; lows within 0.1%

Three-Candle Patterns

c1 = first candle, c2 = middle/star candle, c3 = signal candle.

PatternDirectionKey Conditions
Morning Starbullishc1 bearish (large); c2 small body (star gap down); c3 bullish, closes above c1 midpoint
Evening Starbearishc1 bullish (large); c2 small body (star gap up); c3 bearish, closes below c1 midpoint
Morning Doji Starbullishlike Morning Star but c2 must be a doji (body / range < 5%)
Evening Doji Starbearishlike Evening Star but c2 must be a doji
Three White Soldiersbullish3 consecutive bullish candles; each opens inside prior body, closes higher; upper wick ≤ 20% of body
Three Black Crowsbearish3 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.