Cup and Handle Pattern Detector

v1.0.0

检测股票日线是否符合"杯柄形态(Cup and Handle)"技术分析形态,并生成含轮廓线的识别示意图。触发场景:(1) 询问某只股票是否形成杯柄形态 (2) 查询杯柄形态股票 (3) 技术形态识别需求。触发词:杯柄形态、cup and handle、欧奈尔形态、技术形态识别。

1· 77·0 current·0 all-time
by赖根@laigen

Install

OpenClaw Prompt Flow

Install with OpenClaw

Best for remote or guided setup. Copy the exact prompt, then paste it into OpenClaw for laigen/cup-handle-detector.

Previewing Install & Setup.
Prompt PreviewInstall & Setup
Install the skill "Cup and Handle Pattern Detector" (laigen/cup-handle-detector) from ClawHub.
Skill page: https://clawhub.ai/laigen/cup-handle-detector
Keep the work scoped to this skill only.
After install, inspect the skill metadata and help me finish setup.
Use only the metadata you can verify from ClawHub; do not invent missing requirements.
Ask before making any broader environment changes.

Command Line

CLI Commands

Use the direct CLI path if you want to install manually and keep every step visible.

OpenClaw CLI

Bare skill slug

openclaw skills install cup-handle-detector

ClawHub CLI

Package manager switcher

npx clawhub@latest install cup-handle-detector
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
Name/description, SKILL.md and the two Python scripts are coherent: they implement cup-and-handle detection, visualization, and batch scanning. The dependencies listed (pandas, numpy, matplotlib, optional tushare) match the code's needs.
Instruction Scope
Instructions and scripts work with either: (a) live data via Tushare (requires TUSHARE_TOKEN) or (b) local SQLite DB for batch scans. The scripts read local SQLite DBs (path provided by user) and write images/files to user home/tmp directories. This is expected for the stated purpose but you should be aware the batch script will read any DB file you point it at.
Install Mechanism
No install spec (instruction-only) and the code uses standard Python libraries. SKILL.md lists required Python packages; there are no downloads from untrusted URLs or custom install steps in the package manifest.
Credentials
The code requires TUSHARE_TOKEN (environment variable) when fetching live data via tushare. SKILL.md documents tushare as an optional dependency and notes TUSHARE_TOKEN, but the registry metadata lists no required env vars — this mismatch is informational (token is needed only for live fetches). No other credentials are requested.
Persistence & Privilege
Skill does not request persistent or elevated platform privileges (always:false). It writes output to user-writable dirs under the home/temp areas; it does not modify other skills or system-wide agent settings.
Scan Findings in Context
[USES_ENV_TUSHARE_TOKEN] expected: scripts/cup_handle_detector.py reads TUSHARE_TOKEN from environment when using tushare.pro to fetch live market data; this is expected for live-data retrieval but the registry did not declare the env var as required.
[EXTERNAL_NETWORK_TUSHARE_API] expected: The code uses the tushare/pro API (network access) to obtain daily price data. Network access to Tushare is consistent with the skill's purpose.
[SQL_QUERY_WITH_TABLE_NAME_FSTRING] expected: batch_scan_cup_handle.py constructs a SQL SELECT using the provided table name via an f-string. This is functional for local DB scanning but could be unsafe if untrusted table names are supplied — the script assumes local, user-controlled DB inputs.
Assessment
This skill appears to do what it says: detect cup-and-handle patterns and draw annotated charts. Before installing/running, note: (1) If you want live data, you must provide a TUSHARE_TOKEN (set as an environment variable) and install tushare; SKILL.md documents this but the registry metadata does not list the env var — set it only if you trust tushare and your token. (2) The batch scanner reads any SQLite file you point it to and will save chart files under your home/temp directories — verify the database path and output path before running. (3) There are no hidden network endpoints beyond Tushare and no other credential requests. For safety, run the scripts in a dedicated Python virtual environment, audit the code if you will supply sensitive databases, and only supply your TUSHARE_TOKEN to trusted code/run contexts.

Like a lobster shell, security has layers — review code before you run it.

algorithmic-tradingvk97bqqhapddyk5ba0yt5fcsrz184tctccandlestickvk97bqqhapddyk5ba0yt5fcsrz184tctcchart-analysisvk97bqqhapddyk5ba0yt5fcsrz184tctccup-handlevk97bqqhapddyk5ba0yt5fcsrz184tctcfinancial-analysisvk97bqqhapddyk5ba0yt5fcsrz184tctclatestvk97bqqhapddyk5ba0yt5fcsrz184tctcpattern-detectorvk97bqqhapddyk5ba0yt5fcsrz184tctcstock-analysisvk97bqqhapddyk5ba0yt5fcsrz184tctcstock-patternvk97bqqhapddyk5ba0yt5fcsrz184tctctechnical-analysisvk97bqqhapddyk5ba0yt5fcsrz184tctctradingvk97bqqhapddyk5ba0yt5fcsrz184tctc
77downloads
1stars
1versions
Updated 1w ago
v1.0.0
MIT-0

Cup Handle Detector

检测股票日线数据是否符合经典的"杯柄形态"技术分析形态,并生成可视化识别示意图(含杯柄轮廓线)。

功能特性

  • 形态检测:自动检测杯身(U型底部)和把手(下跌回调)
  • 轮廓绘制:在K线图上绘制杯柄轮廓线(蓝色杯身+橙色把手)
  • 关键标注:标记左杯口、杯底、右杯口、把手等关键点
  • 自适应日期:日期标签自动调整间隔,避免重叠
  • 双语支持:自动检测中文字体,无字体时使用英文标签

依赖要求

必需依赖

依赖版本要求说明
Python≥3.10运行环境
pandas≥1.5数据处理
numpy≥1.20数值计算
matplotlib≥3.6图表生成

可选依赖

依赖用途说明
tushare实时数据获取需配置 TUSHARE_TOKEN 环境变量

中文字体支持

图表标签自动适配:

  • 检测系统中文字体(SimHei、WenQuanYi等)
  • 无中文字体时自动使用英文标签(避免乱码)

快速使用

# 单股票检测(需要 TUSHARE_TOKEN)
python3 scripts/cup_handle_detector.py <股票代码>

# 批量扫描(从SQLite数据库)
python3 scripts/batch_scan_cup_handle.py --db <数据库路径>

示例

python3 scripts/cup_handle_detector.py 600519.SH
python3 scripts/batch_scan_cup_handle.py --db data/stocks.sqlite

输出结果

符合杯柄形态时:

  • 输出形态评分和各项参数
  • 生成含轮廓线的识别示意图(仅显示最近一年数据)
  • 图表保存至临时目录

不符合杯柄形态时:

  • 输出 "不匹配杯柄形态"
  • 不生成图形文件

图表特性

生成的示意图包含:

  • K线蜡烛图(红涨绿跌,最近一年数据)
  • 杯身轮廓线(蓝色U型曲线)
  • 把手轮廓线(橙色回调曲线)
  • 颈线标注(红色虚线,突破位)
  • 关键点标记(左杯口、杯底、右杯口、把手)
  • 形态特征信息框

杯柄形态技术特征

杯柄形态是威廉·欧奈尔提出的经典看涨持续形态。

【重要】最新时间点约束

本检测器只关注最新一段时间内出现的杯柄形态,历史过往形态不属于符合范畴。

具体约束条件:

  • 右杯口距离最新交易日 ≤ 30 天
  • 把手终点距离最新交易日 ≤ 5 天

这意味着形态的最后一个时间点必须是或接近最新的交易日,确保检测到的是当前正在形成或刚完成的形态,而非历史已完成的形态。

杯身(Cup)

  • 形状:U型底部(非V型)
  • 深度:前期涨幅的1/3到1/2(15-33%)
  • 时间跨度:1-6个月(30-180天)

把手(Handle)

  • 位置:位于杯子右侧
  • 形态:向下倾斜或横向整理
  • 深度:不超过杯深的1/3
  • 时间跨度:1-4周(5-30天)

前置趋势

  • 形成前应有明显上升趋势(≥30%涨幅)

算法说明

详见 references/algorithm.md

注意事项

  1. 数据要求:至少需要180天日线数据
  2. 形态主观性:算法评分仅作参考
  3. 风险提示:技术形态仅为参考工具,不构成投资建议

基于威廉·欧奈尔《笑傲股市》CANSLIM投资体系

Comments

Loading comments...