MACD Divergence Backtest (A-Shares)

Detect MACD bullish/bearish divergence signals on A-share historical data and produce a complete backtest report.

✓ 145 reported success·v2.1.0·Updated 2026-04-16

Overview

## Overview MACD divergence is one of the most time-tested trend-reversal signals in technical analysis. This crystal encapsulates a full end-to-end workflow for detecting MACD divergences on A-share equities across daily, 60-minute, and other timeframes. ## Features - Automatically fetches historical OHLCV data for any A-share ticker or index - Computes MACD (EMA 12/26/9) and identifies both bullish and bearish divergences - Generates entry price, stop-loss level, and profit target for each signal - Outputs core performance statistics: win rate, maximum drawdown, and Sharpe ratio - Presents a trade-by-trade record in clean Markdown table format ## Use Cases - Strategy researchers who need to validate whether MACD divergence has predictive power on a specific instrument - Quant beginners learning a complete backtesting workflow from data retrieval to performance reporting - Traders conducting technical post-mortems at key market turning points

Blueprint Source

finance-bp-009

zvtvz/zvta3f762320 source files

Constraints

56total
10fatal
10 must-not-violate

Evidence Quality

Confidence89%

Medium confidence — review before critical use

10 non-negotiable constraints

FATALRCfinance-C-407可自动验证

WHEN实现任何数据 Schema 类时

ACTION继承 Mixin 基类,包含 id(String, primary_key)、entity_id(String)、timestamp(DateTime) 三列

CONSEQUENCE缺少这三列会导致 register_schema、get_data、df_to_db 等全局函数无法正确索引和查询,运行时触发 AttributeError 或 KeyError

FATALRCfinance-C-410可自动验证

WHEN构建 entity_id 时

ACTION使用 {entity_type}_{exchange}_{code} 三段式下划线分隔格式

CONSEQUENCEdecode_entity_id() 使用 split('_') 解析三部分,格式不符会导致 IndexError 或解析出错误的实体类型

FATALRCfinance-C-411可自动验证

WHEN实现自定义 StorageBackend 子类时

ACTION实现 get_engine(storage_id, data_path) 和 get_session_factory(storage_id, data_path) 两个抽象方法

CONSEQUENCEStorageBackend 是全仓库唯一的 ABC,未实现抽象方法会在实例化时抛出 TypeError

FAQ

Community Driven

This crystal was born from 1 community request, with 1 people wanting it

Discussion (1)

@Alice·6 days ago

这个晶体在茅台(600519)的日线上测试效果非常好,底背离信号准确率很高,推荐大家也试试白酒板块。

Changelog

v2.1.02026-04-10·Contributors: @doramagic-team

Initial release.