Skip to content

Repository files navigation

📈 ohlcpattern

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.

License: MITPython: 3.8+Linting: Ruff


✨ Key Features

  • 🚀 Fast Pattern Detection: Optimized with pandas for handling large historical datasets.
  • 🧩 Comprehensive Coverage: Support for 40+ single, double, and triple candlestick patterns.
  • 🛠️ Modern Package Structure: Uses src layout and pyproject.toml for standard installation.
  • 🧪 Test-Driven Development: High reliability with pytest integration.
  • 🧹 Clean Code: Linted and formatted with ruff for maximum readability.

📦 Installation

To install the library with pip:

pip install ohlcpattern

To install the library with uv:

uv sync

For 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 dev

🚀 Quick Start

Ensure your pandas DataFrame contains the standard Open, High, Low, and Close columns.

importpandasaspdfromohlcpattern.candlestickimportCandlestickPatterns# 1. Load your datasetdf=pd.read_csv('market_data.csv', index_col='Date', parse_dates=True)
# 2. Initialize pattern detectorcsp=CandlestickPatterns(df)
# 3. Add detection categories (reversal, continue, or full)csp._add('reversal')
# 4. Generate modeling resultmodeling_data=csp.pattern_modeling()
# 5. Filter for detected patternsdetected=modeling_data[modeling_data.model!='']
print(detected[['Open', 'High', 'Low', 'Close', 'model']])

🖥️ CLI

The package exposes a command-line interface named ohlcpattern.

ohlcpattern --help
ohlcpattern --version
ohlcpattern extract market_data.csv --output patterns.csv
ohlcpattern extract --help

If 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 --help

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


🕯️ Supported Patterns

We support a wide variety of patterns across multiple categories:

Reversal Patterns

BullishBearish
HammerShooting Star
Inverted HammerHanging Man
Bullish EngulfingBearish Engulfing
Morning StarEvening Star
Piercing PatternDark Cloud Cover
Bullish HaramiBearish Harami
Tweezers BottomTweezers Top

Continuation Patterns

  • Gaps: Bullish Gap, Bearish Gap
  • Advanced: Rising/Falling Three Methods, Fair Value Gaps (FVG)
  • Lines: Separating Lines, Neck Patterns

🛠️ Development

We use ruff and pytest for quality insurance.

Running Tests

uv run pytest src tests

Linting & Formatting

uv run ruff check src
uv run ruff format src

📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.


About

Stock Price(Candlestick, Chart) Pattern Modeling(Detection)

Topics

Resources

Stars

16 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages