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

  1. Body size is less than a small percentage of the total range

  2. |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

  1. Previous candle has substantial body

  2. Current candle is a Doji

  3. 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

  1. Open ≈ Close ≈ High

  2. Long lower shadow (> 2× body size)

  3. 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

  1. Open ≈ Close ≈ Low

  2. Long upper shadow (> 2× body size)

  3. 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

  1. Doji pattern

  2. Open/Close near the midpoint of high-low range

  3. 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

  1. Small real body at upper end of trading range

  2. Lower shadow at least 2× the body length

  3. Little or no upper shadow

  4. 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

  1. Same shape as Hammer

  2. 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

  1. Small real body at lower end of range

  2. Long upper shadow (≥ 2× body)

  3. Little or no lower shadow

  4. 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

  1. Same shape as Inverted Hammer

  2. 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

  1. No upper shadow (open or close = high)

  2. 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

  1. Small real body

  2. Upper and lower shadows present

  3. 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

  1. Small real body

  2. Very long upper AND lower shadows

  3. 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

  1. Doji or near-Doji body

  2. Very long lower shadow (> 3× typical)

  3. 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)

  1. Downtrend in progress

  2. First candle: bearish (black/red body)

  3. Second candle: bullish (white/green body)

  4. Second body opens below first body’s low

  5. 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

  1. First candle: long body

  2. Second candle: small body contained within first body

  3. 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

  1. First candle: long body

  2. 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

  1. Downtrend in progress

  2. First candle: long bearish body

  3. Second candle: opens below first’s low

  4. Second candle: closes above midpoint of first’s body

  5. 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

  1. Uptrend in progress

  2. First candle: long bullish body

  3. Second candle: opens above first’s high

  4. Second candle: closes below midpoint of first’s body

  5. 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:

  1. Opens at or near the low

  2. Closes significantly higher

  3. Little or no lower shadow

Bearish: Opposite


CDLCOUNTERATTACK - Counterattack Lines

Two opposite-colored candles with same close.

Detection Rules

  1. First candle: in direction of trend

  2. Second candle: opposite color

  3. Both candles close at same price level


CDLHIKKAKE - Hikkake Pattern

Inside bar breakout failure pattern.

Detection Rules

  1. Inside bar (bar 2 within bar 1)

  2. Breakout in one direction (bar 3)

  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

  1. First candle: long bearish body

  2. Second candle: smaller bearish body contained within first


CDLINNECK - In Neck Pattern

Weak continuation pattern after downtrend.

Detection Rules

  1. Downtrend

  2. First candle: long bearish

  3. 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

  1. First candle: Marubozu (no shadows)

  2. Gap in opposite direction

  3. 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

  1. Two bearish candles

  2. Both close at same price level


CDLTHRUSTING - Thrusting Pattern

Weak bullish pattern - closes into prior body but below midpoint.

Detection Rules

  1. Downtrend

  2. First candle: bearish

  3. Second candle: opens below first’s low

  4. Second candle: closes within first’s body but below midpoint


CDL2CROWS - Two Crows

Bearish continuation after uptrend.

Detection Rules

  1. Uptrend with long bullish first candle

  2. Second candle: bearish, gaps up, closes within first’s body

  3. 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

  1. Downtrend in progress

  2. First candle: long bearish body

  3. Second candle: small body (star), gaps down from first

  4. 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

  1. Uptrend in progress

  2. First candle: long bullish body

  3. Second candle: small body (star), gaps up from first

  4. 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

  1. Three consecutive bullish candles

  2. Each opens within prior body

  3. Each closes at or near its high

  4. 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

  1. Three consecutive bearish candles

  2. Each opens within prior body

  3. Each closes at or near its low

  4. 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)

  1. First two candles form bullish Harami

  2. Third candle closes above first candle’s open


CDL3OUTSIDE - Three Outside Up/Down

Engulfing followed by confirmation candle.

Detection Rules (Three Outside Up)

  1. First two candles form bullish Engulfing

  2. Third candle closes above second candle’s close


CDL3LINESTRIKE - Three Line Strike

Three soldiers/crows followed by opposite Engulfing.

Detection Rules

  1. Three White Soldiers (or Three Black Crows)

  2. 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

  1. Three bearish candles

  2. Each has progressively shorter body

  3. Each has progressively shorter lower shadow

  4. Shows diminishing bearish momentum


CDLABANDONEDBABY - Abandoned Baby

Extreme reversal with island gaps.

Detection Rules

  1. First candle: in trend direction

  2. Second candle: Doji that gaps away (island)

  3. 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

  1. Three bullish candles

  2. Second and third have progressively smaller bodies

  3. 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)

  1. First candle: long bullish

  2. Next 2-4 candles: small bearish, stay within first’s range

  3. 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

  1. Three consecutive Dojis

  2. Middle Doji gaps from first

  3. 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);