Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:TA Lib Ta lib python Candlestick Pattern Detection

From Leeroopedia


Knowledge Sources
Domains Technical_Analysis, Pattern_Recognition
Last Updated 2026-02-09 22:00 GMT

Overview

An algorithmic pattern recognition technique that identifies Japanese candlestick formations in OHLC price data to generate bullish/bearish trading signals.

Description

Japanese candlestick patterns are visual representations of price action that have been used in technical analysis for centuries. Each pattern consists of one or more candles with specific characteristics (body size, shadow length, relationship to adjacent candles).

TA-Lib implements 61 candlestick pattern functions, each detecting a specific formation. Patterns range from single-candle patterns (Doji, Hammer, Marubozu) to complex multi-candle patterns (Three White Soldiers, Morning Star, Engulfing).

Each pattern function analyzes the OHLC data and returns an integer signal array with values:

  • +100: Bullish pattern detected
  • 0: No pattern detected
  • -100: Bearish pattern detected

Usage

Use this principle when you need to detect candlestick patterns in price data for trading signal generation or market analysis.

Theoretical Basis

Candlestick pattern detection evaluates geometric relationships between candle components:

# Abstract pattern detection
# Doji: open approximately equals close
is_doji = abs(close - open) <= threshold * (high - low)

# Engulfing: current candle body completely covers previous
is_bullish_engulfing = (
    prev_close < prev_open  # previous was bearish
    and close > open        # current is bullish
    and open <= prev_close  # current opens below prev close
    and close >= prev_open  # current closes above prev open
)

# Signal encoding
signal = +100 if bullish_pattern else (-100 if bearish_pattern else 0)

The TA-Lib C library uses configurable candle settings (body size thresholds, shadow ratios) via CandleSettingType for adaptive pattern detection.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment