MIT License

项目介绍

djoffrey/HarmonicPatterns 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 142 个 Star、69 次 Fork。

仓库全名
djoffrey/HarmonicPatterns
开源许可证
MIT License
Star 数
142
Fork 数
69
未关闭 Issue
5

README 摘要

HarmonicPatterns A modern, high-performance Python library for detecting and predicting Harmonic Trading Patterns in financial charts. This library filters ZigZag movements and checks if their relationships (retracements/projections) align with standard Fibonacci ratios. 🌟 Features 9 Supported Patterns: Detects ABCD, Gartley, Bat, Alt-Bat, Butterfly, Crab, Deep Crab, Shark, and Cypher. Both Completed & Predicting…

完整内容见 GitHub 原始 README 或本页 。

常见问题

HarmonicPatterns 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 142 个 Star。

HarmonicPatterns 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 HarmonicPatterns 的源码?

可以直接克隆仓库:git clone https://github.com/djoffrey/HarmonicPatterns.git,默认分支为 main;安装与运行步骤见仓库 README。

HarmonicPatterns 最近还在维护吗?

仓库最近一次更新为 6月26日,当前有 5 个未关闭 Issue;Star 数为 142,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

A library written in Python to search harmonic patterns automatically.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
280
价值分
105
活跃状态
活跃

语言占比

Python

README

HarmonicPatterns

A modern, high-performance Python library for detecting and predicting Harmonic Trading Patterns in financial charts. This library filters ZigZag movements and checks if their relationships (retracements/projections) align with standard Fibonacci ratios.


🌟 Features

  • 9 Supported Patterns: Detects ABCD, Gartley, Bat, Alt-Bat, Butterfly, Crab, Deep Crab, Shark, and Cypher.
  • Both Completed & Predicting Scanning: Not only matches historical patterns but also calculates potential D-point targets for incomplete patterns (predicting).
  • Visualization: Seamlessly plots K-lines, moving averages, and detected pattern shapes using mplfinance and saves them to images.
  • Modern Package Management: Powered by uv for reproducible builds and lightning-fast package resolution.

🛠️ Installation

1. Prerequisites (TA-Lib C Library)

This library depends on the python wrapper TA-Lib, which requires the underlying C library to be installed on your machine.

macOS
brew install ta-lib
Linux (Debian/Ubuntu)

Download and compile the source:

wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
./configure --prefix=/usr
make
sudo make install

2. Setting Up the Environment with uv

We recommend using uv (a fast alternative to pip/virtualenv) to manage the virtual environment and dependencies.

First, install uv if you haven’t already:

curl -LsSf https://astral.sh/uv/install.sh | sh

Initialize the virtual environment and install the package in editable mode:

# Create a virtual environment
uv venv

# Lock dependencies and install in editable mode (including requirements)
uv lock
uv pip install -e .

🚀 Quickstart

Here is a simple example to fetch BTC/USDT data and scan for patterns:

import ccxt
from harmonic_patterns import HarmonicDetector, kline_to_df

# 1. Initialize exchange & fetch data
exchange = ccxt.binance()
raw_candles = exchange.fetch_ohlcv('BTC/USDT', '1h', limit=200)
df = kline_to_df(raw_candles)

# 2. Instantiate the detector
# error_allowed=0.05 allows a 5% deviation from standard ratios
detector = HarmonicDetector(error_allowed=0.05, strict=True)

# 3. Detect patterns
# return_dt_idx=True returns timestamps instead of integer index points
patterns, predict_patterns = detector.search_patterns(
    df, 
    only_last=False, 
    last_n=4, 
    plot=True, 
    predict=True,
    return_dt_idx=True,
    save_fig_name='btc_patterns.png'
)

# 4. View results
print(f"Completed patterns: {len(patterns)}")
print(f"Predicting patterns: {len(predict_patterns)}")

📊 Supported Patterns & Fibonacci Ratios

Pattern XA to AB (XAB) AB to BC (ABC) BC to CD (BCD) XA to AD (XAD) / XC to CD (XCD)
ABCD - $0.382 \sim 0.886$ $1.13 \sim 1.168$ $AB = CD$ ($BCD / (1/ABC) = 1$)
Gartley $0.618$ $0.382 \sim 0.886$ $1.13 \sim 1.168$ $XAD = 0.786$
Bat $0.382 \sim 0.5$ $0.382 \sim 0.886$ $1.618 \sim 2.168$ $XAD = 0.886$
Alt-Bat $0.382$ $0.382 \sim 0.886$ $2.0 \sim 3.168$ $XAD = 1.13$
Butterfly $0.786$ $0.382 \sim 0.886$ $1.618 \sim 2.24$ $XAD = 1.27$
Crab $0.382 \sim 0.618$ $0.382 \sim 0.886$ $2.618 \sim 3.618$ $XAD = 1.618$
Deep Crab $0.886$ $0.382 \sim 0.886$ $2.24 \sim 3.618$ $XAD = 1.618$
Shark $0.5 \sim 0.886$ $1.13 \sim 1.618$ $1.618 \sim 2.24$ $XAD = 0.886 \sim 1.13$
Cypher $0.382 \sim 0.786$ $1.272 \sim 1.414$ - $XCD = 0.786$ or $XAD = 0.786$

🏃 Running Examples

We provide a complete, real-time scanning example using OKX market data:

# Run real-time OKX scanning for BTC & ETH
python examples/run_okx_example.py

This will output scan results directly to the terminal, and save visual charts (K-lines with harmonic lines) under the ./data folder.


📂 Project Structure

  • src/: Core library code.
  • examples/: Handy runnable scripts and notebooks.
  • pyproject.toml: Modern PEP-518 project definition.

评论

暂无评论