Candlestick Pattern Recognition
TechKit implements 61 Japanese candlestick patterns, 100% compatible with TA-Lib.
Pattern Output Values
Value |
Meaning |
|---|---|
+100 |
Bullish pattern detected |
-100 |
Bearish pattern detected |
+200 |
Strong bullish pattern |
-200 |
Strong bearish pattern |
0 |
No pattern detected |
API Usage
from techkit import talib_compat as ta
import numpy as np
# Single pattern detection
hammer = ta.CDLHAMMER(open, high, low, close)
# Check for pattern
if hammer[-1] != 0:
print(f"Hammer detected: {hammer[-1]}")
# Scan multiple patterns
patterns = {
'hammer': ta.CDLHAMMER(open, high, low, close),
'engulfing': ta.CDLENGULFING(open, high, low, close),
'doji': ta.CDLDOJI(open, high, low, close),
}
const tk = require('techkit');
// Single pattern
const hammer = tk.CDLHAMMER(open, high, low, close);
// Batch scan all patterns
const results = tk.scanAllPatterns(open, high, low, close);
tk_indicator pat = tk_cdl_hammer_new();
for (int i = 0; i < n; i++) {
tk_ohlcv bar = {open[i], high[i], low[i], close[i], volume[i]};
tk_result r = tk_update_ohlcv(pat, &bar);
if (r.valid && r.value != 0) {
printf("Hammer at bar %d: %.0f\n", i, r.value);
}
}
tk_free(pat);
Pattern Categories
Single Candle Patterns
Patterns formed by analyzing a single candlestick.
CDLDOJI - Doji
A Doji forms when open and close are virtually equal, indicating market indecision.
Visual Pattern
│ Long upper shadow (optional)
│
────┼──── Open ≈ Close (very small body)
│
│ Long lower shadow (optional)
Detection Rules
Body size is less than a small percentage of the total range
|close - open| < threshold × (high - low)
Characteristics
Property |
Value |
|---|---|
Input |
OHLC |
Lookback |
0 |
Output |
0, +100, or -100 |
Trading Usage
Indecision: Neither buyers nor sellers in control
Reversal potential: More significant at trend extremes
Confirmation needed: Wait for next candle to confirm direction
CDLDOJISTAR - Doji Star
A Doji that gaps away from the previous candle.
Visual Pattern
Bullish: Bearish:
■ █
■ █
■ █
─┼─ ─┼─
Detection Rules
Previous candle has substantial body
Current candle is a Doji
Gap between bodies (Doji gaps away from previous close)
Trading Usage
Bullish Doji Star: After downtrend, gaps down = potential reversal up
Bearish Doji Star: After uptrend, gaps up = potential reversal down
CDLDRAGONFLYDOJI - Dragonfly Doji
Doji with long lower shadow and no/minimal upper shadow.
Visual Pattern
────┬──── Open = Close = High
│
│ Long lower shadow
│
│
▼
Detection Rules
Open ≈ Close ≈ High
Long lower shadow (> 2× body size)
No or minimal upper shadow
Trading Usage
Bullish: After downtrend, shows rejection of lower prices
Support: Lower shadow tested and rejected
CDLGRAVESTONEDOJI - Gravestone Doji
Doji with long upper shadow and no/minimal lower shadow.
Visual Pattern
▲
│
│ Long upper shadow
│
│
────┴──── Open = Close = Low
Detection Rules
Open ≈ Close ≈ Low
Long upper shadow (> 2× body size)
No or minimal lower shadow
Trading Usage
Bearish: After uptrend, shows rejection of higher prices
Resistance: Upper shadow tested and rejected
CDLLONGLEGGEDDOJI - Long-Legged Doji
Doji with long shadows on both sides.
Visual Pattern
│
│ Long upper shadow
│
────┼──── Open ≈ Close
│
│ Long lower shadow
│
Trading Usage
High indecision: Both buyers and sellers active
Volatile: Large price range but no net movement
CDLRICKSHAWMAN - Rickshaw Man
Similar to Long-Legged Doji with body at center of range.
Detection Rules
Doji pattern
Open/Close near the midpoint of high-low range
Long shadows on both sides
CDLHAMMER - Hammer
Bullish reversal pattern with small body at top and long lower shadow.
Visual Pattern
┌─┐ Small body at top
│█│
└┬┘
│
│ Long lower shadow (≥ 2× body)
│
▼
Detection Rules
Small real body at upper end of trading range
Lower shadow at least 2× the body length
Little or no upper shadow
Appears after downtrend
Trading Usage
Bullish reversal: Shows rejection of lower prices
Confirmation: Wait for bullish candle next day
Stop loss: Below hammer low
CDLHANGINGMAN - Hanging Man
Same shape as Hammer but appears after uptrend (bearish).
Visual Pattern
Same as Hammer.
Detection Rules
Same shape as Hammer
Appears after uptrend (not downtrend)
Trading Usage
Bearish warning: Potential top formation
Confirmation critical: Needs bearish follow-through
CDLINVERTEDHAMMER - Inverted Hammer
Bullish reversal with small body at bottom and long upper shadow.
Visual Pattern
▲
│
│ Long upper shadow (≥ 2× body)
│
┌┴┐
│█│ Small body at bottom
└─┘
Detection Rules
Small real body at lower end of range
Long upper shadow (≥ 2× body)
Little or no lower shadow
Appears after downtrend
Trading Usage
Bullish reversal potential: But needs confirmation
Less reliable: Than standard Hammer
CDLSHOOTINGSTAR - Shooting Star
Same shape as Inverted Hammer but after uptrend (bearish).
Visual Pattern
Same as Inverted Hammer.
Detection Rules
Same shape as Inverted Hammer
Appears after uptrend
Trading Usage
Bearish reversal: Shows rejection of higher prices
More reliable: With gap up before pattern
CDLMARUBOZU - Marubozu
Full body candle with no shadows.
Visual Pattern
Bullish: Bearish:
┌───┐ ┌───┐
│ │ │███│
│ │ │███│
│ │ │███│
└───┘ └───┘
O=L,C=H O=H,C=L
Detection Rules
No upper shadow (open or close = high)
No lower shadow (open or close = low)
Trading Usage
Strong conviction: Buyers (white) or sellers (black) dominated
Continuation: Often indicates strong trend
CDLLONGLINE - Long Line Candle
Candle with unusually long body.
Detection Rules
Body length > average body length × threshold
Trading Usage
Strong momentum in direction of the candle
CDLSHORTLINE - Short Line Candle
Candle with unusually short body.
Detection Rules
Body length < average body length × threshold
Trading Usage
Weak momentum, potential pause or reversal
CDLSPINNINGTOP - Spinning Top
Small body with shadows on both sides.
Visual Pattern
│
┌┴┐
│█│ Small body
└┬┘
│
Detection Rules
Small real body
Upper and lower shadows present
Not a Doji (has visible body)
Trading Usage
Indecision: Similar to Doji but with small body
Consolidation: Market taking a breather
CDLHIGHWAVE - High Wave Candle
Small body with very long shadows on both sides.
Detection Rules
Small real body
Very long upper AND lower shadows
Shadows significantly longer than typical
Trading Usage
Extreme indecision: Large volatility, no resolution
Reversal potential: At trend extremes
CDLTAKURI - Takuri (Dragonfly Doji with longer shadow)
Dragonfly Doji variant with very long lower shadow.
Detection Rules
Doji or near-Doji body
Very long lower shadow (> 3× typical)
No or minimal upper shadow
Trading Usage
Strong bullish signal: When appearing after downtrend
Extreme rejection: Of lower prices
Two Candle Patterns
Patterns formed by analyzing two consecutive candlesticks.
CDLENGULFING - Engulfing Pattern
Strong reversal pattern where second candle completely engulfs the first.
Visual Pattern
Bullish Engulfing: Bearish Engulfing:
│ ▲
■ Day 1 (bearish) │
■ █ Day 2 (bearish)
│ █
█
▲ █
│ │
█ Day 2 (bullish)
█ ■ Day 1 (bullish)
█ ■
│ │
Detection Rules (Bullish)
Downtrend in progress
First candle: bearish (black/red body)
Second candle: bullish (white/green body)
Second body opens below first body’s low
Second body closes above first body’s high
Characteristics
Property |
Value |
|---|---|
Lookback |
1 |
Output |
+100 (bullish), -100 (bearish) |
Trading Usage
Bullish Engulfing: Strong reversal at bottom, high reliability
Bearish Engulfing: Strong reversal at top
Volume: Higher volume on engulfing candle increases reliability
Entry: On close of engulfing candle or next open
Stop: Below/above engulfing candle’s extreme
CDLHARAMI - Harami Pattern
Second candle’s body contained within first candle’s body.
Visual Pattern
Bullish Harami: Bearish Harami:
│ ▲
■ │
■ █
■─┬─ █─┬─
■ │█│ █ │■│
■─┴─ █─┴─
│ │
Detection Rules
First candle: long body
Second candle: small body contained within first body
Opposite colors (classic) or same color (less reliable)
Trading Usage
Reversal warning: Less reliable than Engulfing
Confirmation needed: Wait for third candle
“Pregnant” pattern: Japanese term harami means pregnant
CDLHARAMICROSS - Harami Cross
Harami where second candle is a Doji.
Detection Rules
First candle: long body
Second candle: Doji contained within first body
Trading Usage
Stronger than regular Harami: Doji adds indecision signal
More reliable reversal indication
CDLPIERCING - Piercing Pattern
Bullish reversal - second candle closes above midpoint of first.
Visual Pattern
│
■ Day 1 (bearish)
■
■
■──── Midpoint
│
│
█ Day 2 opens below Day 1 low
█ closes above Day 1 midpoint
█
▲
Detection Rules
Downtrend in progress
First candle: long bearish body
Second candle: opens below first’s low
Second candle: closes above midpoint of first’s body
Second candle: does not close above first’s open
Trading Usage
Bullish reversal: At support levels
Less strong than Engulfing: Doesn’t fully engulf
CDLDARKCLOUDCOVER - Dark Cloud Cover
Bearish reversal - opposite of Piercing Pattern.
Detection Rules
Uptrend in progress
First candle: long bullish body
Second candle: opens above first’s high
Second candle: closes below midpoint of first’s body
Second candle: does not close below first’s open
Trading Usage
Bearish reversal: At resistance levels
CDLBELTHOLD - Belt Hold
Long candle that opens at extreme and closes opposite.
Visual Pattern
Bullish Belt Hold: Bearish Belt Hold:
▲ │
│ ■ Opens at high
█ ■
█ ■
█ ■ Closes near low
│ Opens at low ▼
Detection Rules
Bullish:
Opens at or near the low
Closes significantly higher
Little or no lower shadow
Bearish: Opposite
CDLCOUNTERATTACK - Counterattack Lines
Two opposite-colored candles with same close.
Detection Rules
First candle: in direction of trend
Second candle: opposite color
Both candles close at same price level
CDLHIKKAKE - Hikkake Pattern
Inside bar breakout failure pattern.
Detection Rules
Inside bar (bar 2 within bar 1)
Breakout in one direction (bar 3)
Reversal back through inside bar (bar 4-5)
CDLHIKKAKEMOD - Modified Hikkake
Variation of Hikkake with additional confirmation.
CDLHOMINGPIGEON - Homing Pigeon
Bullish pattern similar to Harami but both candles bearish.
Detection Rules
First candle: long bearish body
Second candle: smaller bearish body contained within first
CDLINNECK - In Neck Pattern
Weak continuation pattern after downtrend.
Detection Rules
Downtrend
First candle: long bearish
Second candle: opens with gap down, closes at or just below first’s close
CDLONNECK - On Neck Pattern
Similar to In Neck but closes at first’s low.
CDLKICKING - Kicking Pattern
Strong reversal with two Marubozu candles of opposite color with gap.
Visual Pattern
Bullish: Bearish:
┌───┐ ┌───┐
│███│ Day 1 │ │ Day 1
│███│ (bearish) │ │ (bullish)
└───┘ └───┘
↑gap ↓gap
┌───┐ ┌───┐
│ │ Day 2 │███│ Day 2
│ │ (bullish) │███│ (bearish)
└───┘ └───┘
Detection Rules
First candle: Marubozu (no shadows)
Gap in opposite direction
Second candle: Marubozu opposite color
Trading Usage
Very strong signal: Two opposing Marubozus
Rare pattern: High reliability when occurs
CDLKICKINGBYLENGTH - Kicking by Length
Kicking pattern determined by candle length comparison.
CDLMATCHINGLOW - Matching Low
Two candles with same low - support confirmation.
Detection Rules
Two bearish candles
Both close at same price level
CDLTHRUSTING - Thrusting Pattern
Weak bullish pattern - closes into prior body but below midpoint.
Detection Rules
Downtrend
First candle: bearish
Second candle: opens below first’s low
Second candle: closes within first’s body but below midpoint
CDL2CROWS - Two Crows
Bearish continuation after uptrend.
Detection Rules
Uptrend with long bullish first candle
Second candle: bearish, gaps up, closes within first’s body
Third candle: bearish, opens within second, closes within first
Three or More Candle Patterns
Patterns formed by analyzing three or more consecutive candlesticks.
CDLMORNINGSTAR - Morning Star
Strong bullish reversal pattern.
Visual Pattern
Day 1: Day 2: Day 3:
│ ▲
■ │
■ █
■ █
■ ─┼─ █
│ │ │
Detection Rules
Downtrend in progress
First candle: long bearish body
Second candle: small body (star), gaps down from first
Third candle: long bullish body, closes above midpoint of first
Characteristics
Property |
Value |
|---|---|
Lookback |
2 |
Output |
+100 |
Trading Usage
Strong bullish reversal: One of the most reliable patterns
Star gaps important: Larger gap = stronger signal
Entry: On close of third candle
Stop: Below low of the star (second candle)
CDLEVENINGSTAR - Evening Star
Strong bearish reversal pattern (opposite of Morning Star).
Visual Pattern
Day 1: Day 2: Day 3:
▲ │ │
│ ─┼─ ■
█ ■
█ ■
█ ■
│ │
Detection Rules
Uptrend in progress
First candle: long bullish body
Second candle: small body (star), gaps up from first
Third candle: long bearish body, closes below midpoint of first
Trading Usage
Strong bearish reversal: High reliability
CDLMORNINGDOJISTAR - Morning Doji Star
Morning Star where middle candle is a Doji.
Trading Usage
Stronger than regular Morning Star: Doji adds emphasis
CDLEVENINGDOJISTAR - Evening Doji Star
Evening Star where middle candle is a Doji.
CDL3WHITESOLDIERS - Three White Soldiers
Three consecutive long bullish candles.
Visual Pattern
▲
│
▲ █
│ █
▲ █ │
│ █
▲ █ │
│ █
█ │
│
Detection Rules
Three consecutive bullish candles
Each opens within prior body
Each closes at or near its high
Each has a long body
Trading Usage
Strong bullish continuation/reversal: Very reliable
Volume confirmation: Higher volume strengthens signal
CDL3BLACKCROWS - Three Black Crows
Three consecutive long bearish candles (opposite of 3 White Soldiers).
Detection Rules
Three consecutive bearish candles
Each opens within prior body
Each closes at or near its low
Each has a long body
Trading Usage
Strong bearish continuation/reversal: Very reliable
CDL3INSIDE - Three Inside Up/Down
Harami followed by confirmation candle.
Detection Rules (Three Inside Up)
First two candles form bullish Harami
Third candle closes above first candle’s open
CDL3OUTSIDE - Three Outside Up/Down
Engulfing followed by confirmation candle.
Detection Rules (Three Outside Up)
First two candles form bullish Engulfing
Third candle closes above second candle’s close
CDL3LINESTRIKE - Three Line Strike
Three soldiers/crows followed by opposite Engulfing.
Detection Rules
Three White Soldiers (or Three Black Crows)
Fourth candle engulfs all three in opposite direction
Trading Usage
Continuation despite appearance: Usually continues original trend
Counterintuitive: Looks like reversal but often isn’t
CDL3STARSINSOUTH - Three Stars in the South
Bullish reversal showing decreasing selling pressure.
Detection Rules
Three bearish candles
Each has progressively shorter body
Each has progressively shorter lower shadow
Shows diminishing bearish momentum
CDLABANDONEDBABY - Abandoned Baby
Extreme reversal with island gaps.
Detection Rules
First candle: in trend direction
Second candle: Doji that gaps away (island)
Third candle: opposite direction, gaps past Doji
Trading Usage
Very strong reversal: Gap isolation makes it rare and reliable
Rare pattern: Not common but high reliability
CDLADVANCEBLOCK - Advance Block
Weakening of Three White Soldiers pattern.
Detection Rules
Three bullish candles
Second and third have progressively smaller bodies
Long upper shadows on second and/or third
Trading Usage
Weakening uptrend: Bullish momentum fading
CDLBREAKAWAY - Breakaway Pattern
Gap followed by trend, then gap back.
CDLCONCEALBABYSWALL - Concealing Baby Swallow
Rare bullish pattern with two Marubozus.
CDLGAPSIDESIDEWHITE - Up/Down Gap Side-by-Side White Lines
Gap followed by two similar white candles.
CDLIDENTICAL3CROWS - Identical Three Crows
Three Black Crows where each opens at prior close.
CDLLADDERBOTTOM - Ladder Bottom
Five-candle bullish reversal pattern.
CDLMATHOLD - Mat Hold
Five-candle continuation pattern.
CDLRISEFALL3METHODS - Rising/Falling Three Methods
Continuation pattern with consolidation.
Detection Rules (Rising)
First candle: long bullish
Next 2-4 candles: small bearish, stay within first’s range
Final candle: long bullish, closes above first’s close
Trading Usage
Strong continuation: Pause in uptrend then resumption
CDLSEPARATINGLINES - Separating Lines
Opposing candles with same open.
CDLSTALLEDPATTERN - Stalled Pattern
Bullish trend stalling.
CDLSTICKSANDWICH - Stick Sandwich
Two similar bearish candles with bullish between.
CDLTASUKIGAP - Tasuki Gap
Continuation pattern with partial gap fill.
CDLTRISTAR - Tri-Star
Three consecutive Dojis.
Detection Rules
Three consecutive Dojis
Middle Doji gaps from first
Third Doji gaps from second (opposite direction)
Trading Usage
Very rare: Extreme indecision
Strong reversal potential: When it occurs
CDLUNIQUE3RIVER - Unique Three River Bottom
Rare bullish reversal pattern.
CDLUPSIDEGAP2CROWS - Upside Gap Two Crows
Bearish pattern with gap and two crows.
CDLXSIDEGAP3METHODS - Upside/Downside Gap Three Methods
Gap continuation pattern.
Pattern Summary Table
Pattern |
Candles |
Type |
Signal |
|---|---|---|---|
CDLDOJI |
1 |
Neutral |
Indecision |
CDLHAMMER |
1 |
Bullish |
Reversal |
CDLSHOOTINGSTAR |
1 |
Bearish |
Reversal |
CDLENGULFING |
2 |
Both |
Strong Reversal |
CDLHARAMI |
2 |
Both |
Reversal Warning |
CDLPIERCING |
2 |
Bullish |
Reversal |
CDLDARKCLOUDCOVER |
2 |
Bearish |
Reversal |
CDLMORNINGSTAR |
3 |
Bullish |
Strong Reversal |
CDLEVENINGSTAR |
3 |
Bearish |
Strong Reversal |
CDL3WHITESOLDIERS |
3 |
Bullish |
Continuation/Reversal |
CDL3BLACKCROWS |
3 |
Bearish |
Continuation/Reversal |
CDL3INSIDE |
3 |
Both |
Reversal |
CDL3OUTSIDE |
3 |
Both |
Reversal |
CDL3LINESTRIKE |
4 |
Both |
Continuation |
CDLABANDONEDBABY |
3 |
Both |
Strong Reversal |
CDLADVANCEBLOCK |
3 |
Bearish |
Weakening |
CDLRISEFALL3METHODS |
5 |
Both |
Continuation |
CDLTRISTAR |
3 |
Both |
Reversal |
Pattern Scanning
Batch Scanning All Patterns
For efficient pattern detection across all 61 patterns:
from techkit import talib_compat as ta
# Define all pattern functions
PATTERNS = [
('CDL2CROWS', ta.CDL2CROWS),
('CDL3BLACKCROWS', ta.CDL3BLACKCROWS),
('CDL3INSIDE', ta.CDL3INSIDE),
# ... all 61 patterns
]
def scan_all_patterns(open, high, low, close):
results = {}
for name, func in PATTERNS:
pattern = func(open, high, low, close)
# Find non-zero values
signals = [(i, v) for i, v in enumerate(pattern) if v != 0]
if signals:
results[name] = signals
return results
# Usage
detected = scan_all_patterns(open, high, low, close)
for pattern, signals in detected.items():
print(f"{pattern}: {len(signals)} occurrences")
const tk = require('techkit');
// Batch scan
const results = tk.scanAllPatterns(open, high, low, close);
console.log(results);