Candlestick pattern recognition (TA-Lib Pattern Recognition group), translated bar for bar from TA-Lib's C definitions.
Every function takes bars — maps with at least :open, :high,
:low and :close, oldest first — and returns one score per bar,
aligned with the input: 100 bullish, -100 bearish, 0 no
pattern. Bars inside the pattern's lookback score 0. The hikkake
functions follow TA-Lib's confirmation convention: the bar that
confirms a recent setup scores ±200 (the setup's direction), and
engulfing/harami/harami_cross score ±80 when the touching
bodies are merely equal rather than strictly engulfing.
Thresholds are TA-Lib's global candle settings, applied exactly as the C library applies them (each average covers the bars before the candle being judged):
- bodies are long/short against the average real body of the 10 previous candles (factor 1.0), very long at 3x;
- a doji body is under 10% of the average high-low range of the 10 previous candles;
- a shadow is long beyond the candle's own real body, very long beyond 2x, short under half the average shadow sum of the 10 previous candles, very short under 10% of the average high-low range;
- "near"/"far"/"equal" distances are 20%/60%/5% of the average high-low range of the 5 previous candles.
The penetration parameters are fractions of the reference body,
defaulting like TA-Lib (0.3 for the star patterns, 0.5 for the
rest). See TAlib for the remaining conventions.
Summary
Functions
Abandoned Baby: a long candle, a doji gapping away from it, and a third candle gapping beyond the doji to close well within the first body.
Advancing Block: three white candles with higher closes but stalling bodies or upper shadows.
Belt Hold: a long-body candle with a very short shadow on the closing end.
Breakaway: a gap and three drifting candles, then a long candle closing back inside the gap.
Closing Marubozu: a long body with a very short shadow only on the closing end.
Concealing Baby Swallow: two marubozu blacks, a gapping black with an upper shadow into the prior body, engulfed by the fourth black.
Build the candle context of bars once, for reuse across several
pattern calls (each pattern called with plain bars rebuilds it).
Counterattack: two opposite long candles closing at the same level.
Dark Cloud Cover: a long white candle, then a black opening above its high and closing well within its body.
Doji: a body no wider than 10% of the average high-low range of the 10 previous candles.
Doji Star: a long candle then a doji gapping away from its body.
Dragonfly Doji: a doji with a very short upper shadow and a lower shadow beyond the very-short band.
Engulfing: a candle whose body engulfs the previous opposite-color
body — ±80 when the touching bodies are merely equal.
Evening Doji Star: a long white, a doji gapping up, then a black closing well within the first body.
Evening Star: a long white, a short candle gapping up, then a black closing well within the first body.
Upside/Downside Gap Side-by-Side White Lines: two white candles on the same side of a gap, of near-equal body and open.
Gravestone Doji: a doji with a very short lower shadow and an upper shadow beyond the very-short band.
Hammer: a small body near the prior candle's lows with a long lower shadow and a very short upper shadow.
Hanging Man: a small body near the prior candle's highs with a long lower shadow and a very short upper shadow.
Harami: a long candle then a short body inside it — ±80 when the
short body merely touches the long body's ends.
Harami Cross: a long candle then a doji inside it — ±80 when the
doji merely touches the long body's ends.
High Wave: a short body with both shadows longer than twice the body.
Hikkake: an inside bar resolved by a breakout bar, with a ±200
confirmation when a close crosses the setup's extreme within three
bars.
Modified Hikkake: two consecutive inside bars with the second
closing near its extreme, resolved by a breakout bar, with the same
±200 confirmation as hikkake/1.
Homing Pigeon: a long black candle then a smaller black body inside it.
Identical Three Crows: three black candles with very short lower shadows, each opening at the prior close and closing lower.
In Neck: a long black, then a white opening below its low and closing marginally into its body.
Inverted Hammer: after a gap down, a small body with a long upper shadow and a very short lower shadow.
Kicking: two opposite marubozu candles separated by a body gap.
Kicking (determined by length): as kicking/1, scored by the color
of the longer body.
Ladder Bottom: three blacks with lower opens and closes, a black with an upper shadow, then a white closing above its high.
Long Legged Doji: a doji with at least one shadow longer than its own body.
Long Line: a long body with short shadows on both ends.
Marubozu: a long body with very short shadows on both ends.
Mat Hold: a long white, a gap and three small drifting candles holding within it, then a white closing above the reaction highs.
Matching Low: two black candles closing at the same level.
Morning Doji Star: a long black, a doji gapping down, then a white closing well within the first body.
Morning Star: a long black, a short candle gapping down, then a white closing well within the first body.
On Neck: a long black, then a white opening below its low and closing at its low.
Piercing Line: a long black, then a white opening below its low and closing above the midpoint of its body.
Rickshaw Man: a doji with long shadows on both sides and the body near the midpoint of the range.
Rising/Falling Three Methods: a long candle, three small bodies drifting within it, then a long candle closing the move.
Score several patterns over one shared context — equivalent to
calling each pattern on bars, without rebuilding the trailing
sums per pattern. With no pattern list, scores all 61.
Separating Lines: two opposite candles opening at the same level, the second a belt-hold candle.
Shooting Star: after a body gap up, a small body with a long upper shadow and a very short lower shadow.
Short Line: a short body with short shadows on both ends.
Spinning Top: a short body with both shadows longer than the body itself.
Stalled Pattern: two long whites advancing, then a small body riding on the second candle's shoulder.
Stick Sandwich: two blacks around a white whose low holds above the first close, the closes matching.
Takuri: a doji with a very short upper shadow and a lower shadow longer than twice the body.
Tasuki Gap: a gap then a candle opening inside the gap-closing direction with a near-equal body, closing inside the gap.
Three Black Crows: three long black candles opening inside the prior body, closing successively lower with very short lower shadows.
Three Inside: a long candle, a short candle engulfed by it, then a candle closing out in the opposite direction.
Three Line Strike: three same-color candles each opening near the prior body, undone by a fourth that opens beyond and closes across all three.
Three Outside: an engulfing candle followed by a further close in the engulfing direction.
Three Stars in the South: three black candles — long with a long lower shadow, smaller inside it, then a small marubozu engulfed by the second.
Three Advancing White Soldiers: three white candles with consecutive higher closes, each opening near the prior body, none far shorter than its predecessor.
Thrusting: a long black, then a white opening below its low and closing into but under the midpoint of its body.
Tristar: three dojis, the second gapping away and the third failing to extend the gap.
Two Crows: two black candles gapping up after a long white one, the third closing inside the first body.
Unique Three River: a long black, a black harami with a lower low, then a small white opening off the low.
Upside Gap Two Crows: a long white, then two blacks gapping up with the third engulfing the second but closing above the first.
Upside/Downside Gap Three Methods: a gap between two same-color candles, partially closed by a third of the opposite color.
Functions
Abandoned Baby: a long candle, a doji gapping away from it, and a third candle gapping beyond the doji to close well within the first body.
iex> TAlib.Indicators.CDL.abandoned_baby([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Advancing Block: three white candles with higher closes but stalling bodies or upper shadows.
iex> TAlib.Indicators.CDL.advance_block([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Belt Hold: a long-body candle with a very short shadow on the closing end.
iex> bars = Enum.map(0..9, fn _ -> %{open: 0.0, high: 2.0, low: 0.0, close: 1.0} end)
iex> TAlib.Indicators.CDL.belt_hold(bars) |> Enum.all?(&(&1 == 0))
true
Breakaway: a gap and three drifting candles, then a long candle closing back inside the gap.
iex> TAlib.Indicators.CDL.breakaway([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Closing Marubozu: a long body with a very short shadow only on the closing end.
iex> bars = Enum.map(0..9, fn _ -> %{open: 0.0, high: 2.0, low: 0.0, close: 1.0} end)
iex> TAlib.Indicators.CDL.closing_marubozu(bars) |> Enum.all?(&(&1 == 0))
true
Concealing Baby Swallow: two marubozu blacks, a gapping black with an upper shadow into the prior body, engulfed by the fourth black.
iex> TAlib.Indicators.CDL.conceal_babys_wall([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Build the candle context of bars once, for reuse across several
pattern calls (each pattern called with plain bars rebuilds it).
iex> ctx = TAlib.Indicators.CDL.context([%{open: 1, high: 2, low: 0.5, close: 1.5}])
iex> TAlib.Indicators.CDL.doji(ctx)
[0]
Counterattack: two opposite long candles closing at the same level.
iex> TAlib.Indicators.CDL.counterattack([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Dark Cloud Cover: a long white candle, then a black opening above its high and closing well within its body.
iex> TAlib.Indicators.CDL.dark_cloud_cover([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Doji: a body no wider than 10% of the average high-low range of the 10 previous candles.
iex> bars = Enum.map(0..9, fn _ -> %{open: 0.0, high: 2.0, low: 0.0, close: 1.0} end)
iex> TAlib.Indicators.CDL.doji(bars ++ [%{open: 1.0, high: 2.0, low: 0.0, close: 1.01}]) |> List.last()
100
Doji Star: a long candle then a doji gapping away from its body.
iex> TAlib.Indicators.CDL.doji_star([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Dragonfly Doji: a doji with a very short upper shadow and a lower shadow beyond the very-short band.
iex> TAlib.Indicators.CDL.dragonfly_doji([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Engulfing: a candle whose body engulfs the previous opposite-color
body — ±80 when the touching bodies are merely equal.
iex> TAlib.Indicators.CDL.engulfing([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Evening Doji Star: a long white, a doji gapping up, then a black closing well within the first body.
iex> TAlib.Indicators.CDL.evening_doji_star([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Evening Star: a long white, a short candle gapping up, then a black closing well within the first body.
iex> TAlib.Indicators.CDL.evening_star([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Upside/Downside Gap Side-by-Side White Lines: two white candles on the same side of a gap, of near-equal body and open.
iex> TAlib.Indicators.CDL.gap_side_side_white([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Gravestone Doji: a doji with a very short lower shadow and an upper shadow beyond the very-short band.
iex> TAlib.Indicators.CDL.gravestone_doji([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Hammer: a small body near the prior candle's lows with a long lower shadow and a very short upper shadow.
iex> TAlib.Indicators.CDL.hammer([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Hanging Man: a small body near the prior candle's highs with a long lower shadow and a very short upper shadow.
iex> TAlib.Indicators.CDL.hanging_man([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Harami: a long candle then a short body inside it — ±80 when the
short body merely touches the long body's ends.
iex> TAlib.Indicators.CDL.harami([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Harami Cross: a long candle then a doji inside it — ±80 when the
doji merely touches the long body's ends.
iex> TAlib.Indicators.CDL.harami_cross([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
High Wave: a short body with both shadows longer than twice the body.
iex> TAlib.Indicators.CDL.high_wave([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Hikkake: an inside bar resolved by a breakout bar, with a ±200
confirmation when a close crosses the setup's extreme within three
bars.
iex> bars = [
...> %{open: 1.0, high: 10.0, low: 0.0, close: 5.0},
...> %{open: 1.0, high: 9.0, low: 1.0, close: 5.0},
...> %{open: 1.0, high: 8.0, low: 0.5, close: 5.0},
...> %{open: 1.0, high: 8.5, low: 0.6, close: 5.0},
...> %{open: 1.0, high: 8.4, low: 0.7, close: 5.0},
...> %{open: 1.0, high: 8.6, low: 0.65, close: 9.5}
...> ]
iex> TAlib.Indicators.CDL.hikkake(bars)
[0, 0, 0, 0, 0, 200]
Modified Hikkake: two consecutive inside bars with the second
closing near its extreme, resolved by a breakout bar, with the same
±200 confirmation as hikkake/1.
iex> TAlib.Indicators.CDL.hikkake_mod([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Homing Pigeon: a long black candle then a smaller black body inside it.
iex> TAlib.Indicators.CDL.homing_pigeon([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Identical Three Crows: three black candles with very short lower shadows, each opening at the prior close and closing lower.
iex> TAlib.Indicators.CDL.identical_3_crows([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
In Neck: a long black, then a white opening below its low and closing marginally into its body.
iex> TAlib.Indicators.CDL.in_neck([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Inverted Hammer: after a gap down, a small body with a long upper shadow and a very short lower shadow.
iex> TAlib.Indicators.CDL.inverted_hammer([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Kicking: two opposite marubozu candles separated by a body gap.
iex> TAlib.Indicators.CDL.kicking([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Kicking (determined by length): as kicking/1, scored by the color
of the longer body.
iex> TAlib.Indicators.CDL.kicking_by_length([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Ladder Bottom: three blacks with lower opens and closes, a black with an upper shadow, then a white closing above its high.
iex> TAlib.Indicators.CDL.ladder_bottom([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Long Legged Doji: a doji with at least one shadow longer than its own body.
iex> TAlib.Indicators.CDL.long_legged_doji([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Long Line: a long body with short shadows on both ends.
iex> bars = Enum.map(0..9, fn _ -> %{open: 0.0, high: 2.0, low: 0.0, close: 1.0} end)
iex> TAlib.Indicators.CDL.long_line(bars) |> Enum.all?(&(&1 == 0))
true
Marubozu: a long body with very short shadows on both ends.
iex> bars = Enum.map(0..9, fn _ -> %{open: 0.0, high: 2.0, low: 0.0, close: 1.0} end)
iex> TAlib.Indicators.CDL.marubozu(bars) |> Enum.all?(&(&1 == 0))
true
Mat Hold: a long white, a gap and three small drifting candles holding within it, then a white closing above the reaction highs.
iex> TAlib.Indicators.CDL.mat_hold([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Matching Low: two black candles closing at the same level.
iex> TAlib.Indicators.CDL.matching_low([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Morning Doji Star: a long black, a doji gapping down, then a white closing well within the first body.
iex> TAlib.Indicators.CDL.morning_doji_star([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Morning Star: a long black, a short candle gapping down, then a white closing well within the first body.
iex> TAlib.Indicators.CDL.morning_star([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
On Neck: a long black, then a white opening below its low and closing at its low.
iex> TAlib.Indicators.CDL.on_neck([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Piercing Line: a long black, then a white opening below its low and closing above the midpoint of its body.
iex> TAlib.Indicators.CDL.piercing([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Rickshaw Man: a doji with long shadows on both sides and the body near the midpoint of the range.
iex> TAlib.Indicators.CDL.rickshaw_man([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Rising/Falling Three Methods: a long candle, three small bodies drifting within it, then a long candle closing the move.
iex> TAlib.Indicators.CDL.rise_fall_3_methods([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
scan(bars, patterns \\ [:two_crows, :three_black_crows, :three_inside, :three_line_strike, :three_outside, :three_stars_in_south, :three_white_soldiers, :abandoned_baby, :advance_block, :belt_hold, :breakaway, :closing_marubozu, :conceal_babys_wall, :counterattack, :dark_cloud_cover, :doji, :doji_star, :dragonfly_doji, :engulfing, :evening_doji_star, :evening_star, :gap_side_side_white, :gravestone_doji, :hammer, :hanging_man, :harami, :harami_cross, :high_wave, :hikkake, :hikkake_mod, :homing_pigeon, :identical_3_crows, :in_neck, :inverted_hammer, :kicking, :kicking_by_length, :ladder_bottom, :long_legged_doji, :long_line, :marubozu, :matching_low, :mat_hold, :morning_doji_star, :morning_star, :on_neck, :piercing, :rickshaw_man, :rise_fall_3_methods, :separating_lines, :shooting_star, :short_line, :spinning_top, :stalled_pattern, :stick_sandwich, :takuri, :tasuki_gap, :thrusting, :tristar, :unique_3_river, :upside_gap_2crows, :xside_gap_3methods])
Score several patterns over one shared context — equivalent to
calling each pattern on bars, without rebuilding the trailing
sums per pattern. With no pattern list, scores all 61.
iex> bars = Enum.map(0..9, fn _ -> %{open: 0.0, high: 2.0, low: 0.0, close: 1.0} end)
iex> TAlib.Indicators.CDL.scan(bars ++ [%{open: 1.0, high: 2.0, low: 0.0, close: 1.01}], [:doji])[:doji] |> List.last()
100
Separating Lines: two opposite candles opening at the same level, the second a belt-hold candle.
iex> TAlib.Indicators.CDL.separating_lines([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Shooting Star: after a body gap up, a small body with a long upper shadow and a very short lower shadow.
iex> TAlib.Indicators.CDL.shooting_star([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Short Line: a short body with short shadows on both ends.
iex> bars = Enum.map(0..9, fn _ -> %{open: 0.0, high: 2.0, low: 0.0, close: 1.0} end)
iex> TAlib.Indicators.CDL.short_line(bars) |> Enum.all?(&(&1 == 0))
true
Spinning Top: a short body with both shadows longer than the body itself.
iex> TAlib.Indicators.CDL.spinning_top([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Stalled Pattern: two long whites advancing, then a small body riding on the second candle's shoulder.
iex> TAlib.Indicators.CDL.stalled_pattern([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Stick Sandwich: two blacks around a white whose low holds above the first close, the closes matching.
iex> TAlib.Indicators.CDL.stick_sandwich([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Takuri: a doji with a very short upper shadow and a lower shadow longer than twice the body.
iex> TAlib.Indicators.CDL.takuri([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Tasuki Gap: a gap then a candle opening inside the gap-closing direction with a near-equal body, closing inside the gap.
iex> TAlib.Indicators.CDL.tasuki_gap([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Three Black Crows: three long black candles opening inside the prior body, closing successively lower with very short lower shadows.
iex> TAlib.Indicators.CDL.three_black_crows([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Three Inside: a long candle, a short candle engulfed by it, then a candle closing out in the opposite direction.
iex> TAlib.Indicators.CDL.three_inside([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Three Line Strike: three same-color candles each opening near the prior body, undone by a fourth that opens beyond and closes across all three.
iex> TAlib.Indicators.CDL.three_line_strike([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Three Outside: an engulfing candle followed by a further close in the engulfing direction.
iex> TAlib.Indicators.CDL.three_outside([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Three Stars in the South: three black candles — long with a long lower shadow, smaller inside it, then a small marubozu engulfed by the second.
iex> TAlib.Indicators.CDL.three_stars_in_south([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Three Advancing White Soldiers: three white candles with consecutive higher closes, each opening near the prior body, none far shorter than its predecessor.
iex> bars = Enum.map(0..11, fn _ -> %{open: 0.0, high: 2.0, low: 0.0, close: 1.0} end)
iex> TAlib.Indicators.CDL.three_white_soldiers(bars) |> Enum.all?(&(&1 == 0))
true
Thrusting: a long black, then a white opening below its low and closing into but under the midpoint of its body.
iex> TAlib.Indicators.CDL.thrusting([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Tristar: three dojis, the second gapping away and the third failing to extend the gap.
iex> TAlib.Indicators.CDL.tristar([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Two Crows: two black candles gapping up after a long white one, the third closing inside the first body.
iex> TAlib.Indicators.CDL.two_crows([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Unique Three River: a long black, a black harami with a lower low, then a small white opening off the low.
iex> TAlib.Indicators.CDL.unique_3_river([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Upside Gap Two Crows: a long white, then two blacks gapping up with the third engulfing the second but closing above the first.
iex> TAlib.Indicators.CDL.upside_gap_2crows([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]
Upside/Downside Gap Three Methods: a gap between two same-color candles, partially closed by a third of the opposite color.
iex> TAlib.Indicators.CDL.xside_gap_3methods([%{open: 1, high: 2, low: 0.5, close: 1.5}])
[0]