ohlcpattern is a modern, high-performance Python library for detecting candlestick patterns in financial data. Built with pandas and designed for speed and ease of use, it helps traders and quantitative analysts model and identify over 40+ different market signals.
- 🚀 Fast Pattern Detection: Optimized with
pandasfor handling large historical datasets. - 🧩 Comprehensive Coverage: Support for 40+ single, double, and triple candlestick patterns.
- 🛠️ Modern Package Structure: Uses
srclayout andpyproject.tomlfor standard installation. - 🧪 Test-Driven Development: High reliability with
pytestintegration. - 🧹 Clean Code: Linted and formatted with
rufffor maximum readability.
To install the library with pip:
pip install ohlcpatternTo install the library with uv:
uv syncFor development, install with optional dependencies using pip:
git clone https://github.com/yourusername/ohlcpattern.git
cd ohlcpattern
pip install -e ".[dev]"Or use uv:
git clone https://github.com/yourusername/ohlcpattern.git
cd ohlcpattern
uv sync --extra devEnsure your pandas DataFrame contains the standard Open, High, Low, and Close columns.
import pandas as pd
from ohlcpattern.candlestick import CandlestickPatterns
# 1. Load your dataset
df = pd.read_csv('market_data.csv', index_col='Date', parse_dates=True)
# 2. Initialize pattern detector
csp = CandlestickPatterns(df)
# 3. Add detection categories (reversal, continue, or full)
csp._add('reversal')
# 4. Generate modeling result
modeling_data = csp.pattern_modeling()
# 5. Filter for detected patterns
detected = modeling_data[modeling_data.model != '']
print(detected[['Open', 'High', 'Low', 'Close', 'model']])The package exposes a command-line interface named ohlcpattern.
ohlcpattern --help
ohlcpattern --version
ohlcpattern extract market_data.csv --output patterns.csv
ohlcpattern extract --helpIf you prefer running it through uv:
uv run ohlcpattern --help
uv run ohlcpattern --version
uv run ohlcpattern extract market_data.csv --output patterns.csv
uv run ohlcpattern extract --helpThe extract command expects a CSV file with Open, High, Low, and Close columns. If --output is omitted, it prints a preview of detected patterns to the terminal.
We support a wide variety of patterns across multiple categories:
| Bullish | Bearish |
|---|---|
| Hammer | Shooting Star |
| Inverted Hammer | Hanging Man |
| Bullish Engulfing | Bearish Engulfing |
| Morning Star | Evening Star |
| Piercing Pattern | Dark Cloud Cover |
| Bullish Harami | Bearish Harami |
| Tweezers Bottom | Tweezers Top |
- Gaps: Bullish Gap, Bearish Gap
- Advanced: Rising/Falling Three Methods, Fair Value Gaps (FVG)
- Lines: Separating Lines, Neck Patterns
We use ruff and pytest for quality insurance.
uv run pytest src testsuv run ruff check src
uv run ruff format srcThis project is licensed under the MIT License. See the LICENSE file for more details.