Recognise 15 classic candlestick patterns in every ticker’s candles, with the definitions of TA-Lib’s CDL functions. Candlestick charting reads the open, high, low and close of a period as one candle: the real body between the open and the close and the shadows up to the high and down to the low. Certain shapes and sequences are read as a sign that a move is ending or continuing.

Each pattern is 1 on the candle that completes it as a bullish pattern, -1 as a bearish pattern and 0 otherwise (TA-Lib’s +100 and -100 divided by 100). The weaker engulfing and harami, where one end of the two real bodies is equal, are 0.8 and -0.8 (TA-Lib’s 80). The doji is indecision rather than a direction and is 1 when present; a marubozu and a spinning top take the colour of the candle (1 white, -1 black).

The patterns:

  • Doji: an open and close nearly equal.
  • Hammer (bullish) and Hanging Man (bearish): a short real body at the top of a long lower shadow, near the previous low or the previous high respectively.
  • Inverted Hammer (bullish) and Shooting Star (bearish): a short real body at the bottom of a long upper shadow that gaps down or up from the previous real body.
  • Engulfing: a real body that engulfs the previous real body of the opposite colour.
  • Harami: a short real body inside the previous long real body, opposite to its colour.
  • Piercing Line (bullish) and Dark Cloud Cover (bearish): a long candle followed by one of the opposite colour that opens beyond the previous low (high) and closes past the middle of the previous real body.
  • Morning Star (bullish) and Evening Star (bearish): a long real body, a short real body that gaps away from it and a real body of the opposite colour that closes at least 30% into the first.
  • Three White Soldiers (bullish) and Three Black Crows (bearish): three long-enough candles of one colour with ever higher (lower) closes, each opening within the previous real body.
  • Marubozu: a long real body with (almost) no shadows.
  • Spinning Top: a short real body with both shadows longer than the body.

Sizes are relative to the ticker’s own recent candles, as in TA-Lib: a real body is long (short) when it is longer (shorter) than the average real body of the 10 previous candles, a doji’s body is at most 10% and a very short shadow less than 10% of their average high-low range, a long shadow is longer than the candle’s own real body, and “near” is within 20% and “far” at least 60% of the average high-low range of the 5 previous candles.

For more information, see the following books:

  • Nison, S. (1991). “Japanese Candlestick Charting Techniques.” New York Institute of Finance.
  • Bulkowski, T.N. (2008). “Encyclopedia of Candlestick Charts.” Wiley.

Also known as: candlestick patterns, candle patterns, CDL, Japanese candlesticks.

Candlestick Patterns in Python

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_candlestick_patterns as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2025-01-01",
    end_date="2025-12-31",
)

patterns = toolkit.technicals.get_candlestick_patterns()

engulfing = patterns["Engulfing"]
engulfing[engulfing.ne(0).any(axis=1)].tail()

Which returns:

Date AAPL MSFT Benchmark
2025-12-10 0 0 1
2025-12-15 -1 0 0
2025-12-17 -1 0 0
2025-12-19 1 0 0
2025-12-31 0 -1 0

Parameters

get_candlestick_patterns accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Can be “intraday”, “daily”, “weekly”, “monthly”, “quarterly” or “yearly”. Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”, in which case the open, high and low prices are adjusted for dividends in the same way, so an ex-dividend day doesn’t read as a gap. “Close” uses the candles as traded (split-adjusted)."Close"
patternsstr | list[str] | NoneThe patterns to return, e.g. [“Hammer”, “Engulfing”]. Defaults to None, which returns all 15.None, which returns all 15
Share