Files
beast-trader/docs/v2_2d_strategy_manual.html

1550 lines
82 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Structure Flow Strategy v2.2d — 完整策略说明书</title>
<style>
@page {
size: A4;
margin: 18mm 18mm 22mm 18mm;
@bottom-center {
content: "— " counter(page) " —";
font-size: 9pt;
color: #888;
font-family: "Georgia", serif;
}
}
@page :first {
@bottom-center { content: none; }
margin: 0;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: "Noto Serif SC", "SimSun", "STSong", "Songti SC", Georgia, serif;
font-size: 11pt;
line-height: 1.75;
color: #1a1a1a;
width: 100%;
max-width: 174mm;
margin: 0 auto;
padding: 0;
background: #fff;
}
/* ── Cover ── */
.cover {
page-break-after: always;
width: 100%;
min-height: 297mm;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
background: linear-gradient(160deg, #0a0e27 0%, #1a1f3a 40%, #0a0e27 100%);
color: #e8e8e8;
position: relative;
overflow: hidden;
margin: 0;
padding: 0;
}
.cover::before {
content: "";
position: absolute;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: radial-gradient(ellipse at 30% 20%, rgba(59,130,246,0.15) 0%, transparent 60%),
radial-gradient(ellipse at 70% 80%, rgba(239,68,68,0.12) 0%, transparent 60%);
animation: none;
}
.cover-content {
position: relative;
z-index: 1;
padding: 0 40px;
}
.cover-tag {
display: inline-block;
border: 1.5px solid rgba(59,130,246,0.6);
color: #60a5fa;
padding: 6px 24px;
border-radius: 2px;
font-size: 11pt;
letter-spacing: 4px;
margin-bottom: 36px;
font-family: "SF Mono", "Consolas", monospace;
}
.cover h1 {
font-size: 34pt;
font-weight: 700;
letter-spacing: 3px;
margin-bottom: 16px;
color: #fff;
line-height: 1.3;
}
.cover h2 {
font-size: 16pt;
font-weight: 300;
color: #94a3b8;
letter-spacing: 1px;
margin-bottom: 48px;
}
.cover-meta {
font-size: 10pt;
color: #64748b;
line-height: 2.0;
}
.cover-line {
width: 60px;
height: 1px;
background: rgba(148,163,184,0.4);
margin: 36px auto;
}
/* ── TOC ── */
.toc {
page-break-after: always;
padding: 40px 0;
}
.toc h2 {
font-size: 18pt;
margin-bottom: 24px;
border-bottom: 2px solid #1a1a1a;
padding-bottom: 10px;
}
.toc-list { list-style: none; }
.toc-list li {
padding: 6px 0;
border-bottom: 1px dotted #ccc;
}
.toc-list a {
color: #1a1a1a;
text-decoration: none;
display: flex;
justify-content: space-between;
}
.toc-list .toc-num { color: #3b82f6; font-weight: 600; min-width: 28px; }
.toc-list .toc-page { color: #888; font-family: "SF Mono", monospace; font-size: 9.5pt; }
.toc-sub { padding-left: 28px !important; font-size: 10pt; }
/* ── Chapters ── */
.chapter {
page-break-before: always;
padding-top: 20px;
}
.chapter h2 {
font-size: 20pt;
font-weight: 700;
margin-bottom: 6px;
padding-bottom: 8px;
border-bottom: 3px solid #1a1a1a;
letter-spacing: 1px;
}
.chapter .ch-num {
display: block;
font-size: 11pt;
color: #3b82f6;
font-weight: 600;
letter-spacing: 3px;
margin-bottom: 4px;
}
h3 {
font-size: 14pt;
margin-top: 28px;
margin-bottom: 12px;
color: #1a1a1a;
}
h4 {
font-size: 12pt;
margin-top: 20px;
margin-bottom: 8px;
color: #333;
}
p { margin-bottom: 10px; text-align: justify; }
ul, ol { margin: 8px 0 12px 24px; }
li { margin-bottom: 4px; }
strong { color: #0a0e27; }
em { color: #555; }
/* ── Tables ── */
table {
width: 100%;
border-collapse: collapse;
margin: 14px 0;
font-size: 9.5pt;
table-layout: auto;
word-break: break-word;
}
th {
background: #1a1f3a;
color: #e8e8e8;
padding: 7px 8px;
text-align: left;
font-weight: 600;
font-size: 9pt;
white-space: nowrap;
}
td {
padding: 6px 8px;
border-bottom: 1px solid #e5e7eb;
vertical-align: top;
}
tr:nth-child(even) td { background: #f8f9fb; }
.table-note { font-size: 9pt; color: #888; margin-top: 4px; }
/* ── Highlight boxes ── */
.highlight {
background: #eff6ff;
border-left: 4px solid #3b82f6;
padding: 14px 18px;
margin: 16px 0;
font-size: 10.5pt;
}
.highlight-red {
background: #fef2f2;
border-left: 4px solid #ef4444;
}
.highlight-green {
background: #f0fdf4;
border-left: 4px solid #22c55e;
}
.highlight-amber {
background: #fffbeb;
border-left: 4px solid #f59e0b;
}
/* ── Code ── */
code {
font-family: "SF Mono", "Consolas", "Courier New", monospace;
font-size: 9.5pt;
background: #f1f5f9;
padding: 1px 5px;
border-radius: 2px;
}
pre {
background: #0f172a;
color: #e2e8f0;
padding: 14px 18px;
font-size: 9pt;
line-height: 1.55;
overflow-x: auto;
margin: 12px 0;
border-radius: 4px;
}
pre code { background: none; padding: 0; color: inherit; }
/* ── Figure ── */
.figure {
margin: 18px 0;
text-align: center;
max-width: 100%;
overflow-x: hidden;
}
.figure svg {
max-width: 100%;
height: auto;
display: block;
margin: 0 auto;
}
.figure-caption {
font-size: 9pt;
color: #666;
margin-top: 8px;
font-style: italic;
max-width: 100%;
}
/* ── Metrics grid ── */
.metrics-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 12px;
margin: 16px 0;
}
.metric-card {
background: #f8f9fb;
border: 1px solid #e5e7eb;
padding: 12px 14px;
text-align: center;
border-radius: 4px;
}
.metric-card .val {
font-size: 18pt;
font-weight: 700;
color: #1a1f3a;
line-height: 1.2;
}
.metric-card .lbl {
font-size: 9pt;
color: #888;
margin-top: 4px;
text-transform: uppercase;
letter-spacing: 1px;
}
.metric-card.green .val { color: #16a34a; }
.metric-card.red .val { color: #dc2626; }
.metric-card.blue .val { color: #2563eb; }
/* ── Print fixes ── */
@media print {
body {
font-size: 9.5pt;
line-height: 1.65;
max-width: 100%;
padding: 0;
}
.cover {
height: 297mm;
width: 210mm;
max-width: 210mm;
margin: 0;
padding: 0;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
.chapter { page-break-before: always; page-break-after: auto; }
.toc { page-break-after: always; }
h2 { page-break-after: avoid; }
h3 { page-break-after: avoid; page-break-before: auto; }
h4 { page-break-after: avoid; }
table {
page-break-inside: avoid;
font-size: 8.5pt;
}
.highlight { page-break-inside: avoid; }
pre {
page-break-inside: avoid;
font-size: 8pt;
white-space: pre-wrap;
word-break: break-all;
}
.figure {
page-break-inside: avoid;
max-width: 100%;
}
.figure svg {
max-width: 100%;
height: auto;
}
.metrics-grid { page-break-inside: avoid; }
ul, ol { page-break-inside: avoid; }
p { orphans: 3; widows: 3; }
}
</style>
</head>
<body>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- COVER -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="cover">
<div class="cover-content">
<div class="cover-tag">STRATEGY MANUAL</div>
<h1>Structure Flow Strategy<br>v2.2d</h1>
<h2>ETH/USDT 永续合约 · 中低频价格行为趋势跟踪</h2>
<div class="cover-line"></div>
<div class="cover-meta">
作者FXY<br>
版本v2.2d(冷却期修复版)<br>
日期2026年6月11日<br>
引擎Freqtrade 2026.2 + Binance Futures<br>
品种ETH/USDT:USDT · 时间框架1H · 杠杆1x
</div>
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- TOC -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="toc">
<h2>目 录</h2>
<ol class="toc-list">
<li><a href="#ch1"><span class="toc-num"></span> 策略总览与设计哲学</a></li>
<li class="toc-sub"><a href="#ch1-1">1.1 策略定位</a></li>
<li class="toc-sub"><a href="#ch1-2">1.2 设计哲学:纯价格行为学</a></li>
<li class="toc-sub"><a href="#ch1-3">1.3 第一性原理</a></li>
<li><a href="#ch2"><span class="toc-num"></span> 系统架构与数据流</a></li>
<li class="toc-sub"><a href="#ch2-1">2.1 多时间框架架构</a></li>
<li class="toc-sub"><a href="#ch2-2">2.2 数据处理流程</a></li>
<li class="toc-sub"><a href="#ch2-3">2.3 参数一览</a></li>
<li><a href="#ch3"><span class="toc-num"></span> 核心组件:价格结构识别</a></li>
<li class="toc-sub"><a href="#ch3-1">3.1 Swing Point 检测算法</a></li>
<li class="toc-sub"><a href="#ch3-2">3.2 结构分析:趋势判断与 S/R 定位</a></li>
<li class="toc-sub"><a href="#ch3-3">3.3 供需区域划分</a></li>
<li><a href="#ch4"><span class="toc-num"></span> 核心组件K线形态识别</a></li>
<li class="toc-sub"><a href="#ch4-1">4.1 Pin Bar 检测</a></li>
<li class="toc-sub"><a href="#ch4-2">4.2 吞没形态检测</a></li>
<li class="toc-sub"><a href="#ch4-3">4.3 形态在策略中的角色</a></li>
<li><a href="#ch5"><span class="toc-num"></span> 入场条件详解</a></li>
<li class="toc-sub"><a href="#ch5-1">5.1 做多入场6项条件</a></li>
<li class="toc-sub"><a href="#ch5-2">5.2 做空入场6项条件</a></li>
<li class="toc-sub"><a href="#ch5-3">5.3 入场决策流程图</a></li>
<li><a href="#ch6"><span class="toc-num"></span> 冷却期机制v2.2c → v2.2d 关键修复</a></li>
<li class="toc-sub"><a href="#ch6-1">6.1 v2.2c 的致命 Bug</a></li>
<li class="toc-sub"><a href="#ch6-2">6.2 v2.2d 修复方案</a></li>
<li class="toc-sub"><a href="#ch6-3">6.3 修复效果对比</a></li>
<li><a href="#ch7"><span class="toc-num"></span> 出场逻辑</a></li>
<li class="toc-sub"><a href="#ch7-1">7.1 结构出场信号</a></li>
<li class="toc-sub"><a href="#ch7-2">7.2 动态止损Custom Stoploss</a></li>
<li class="toc-sub"><a href="#ch7-3">7.3 出场逻辑完整流程</a></li>
<li><a href="#ch8"><span class="toc-num"></span> 风险管理</a></li>
<li class="toc-sub"><a href="#ch8-1">8.1 硬止损上限</a></li>
<li class="toc-sub"><a href="#ch8-2">8.2 仓位控制</a></li>
<li class="toc-sub"><a href="#ch8-3">8.3 最大回撤分析</a></li>
<li><a href="#ch9"><span class="toc-num"></span> 回测结果完整分析</a></li>
<li class="toc-sub"><a href="#ch9-1">9.1 核心指标摘要</a></li>
<li class="toc-sub"><a href="#ch9-2">9.2 出场原因分布</a></li>
<li class="toc-sub"><a href="#ch9-3">9.3 多空表现对比</a></li>
<li class="toc-sub"><a href="#ch9-4">9.4 盈亏分布特征</a></li>
<li class="toc-sub"><a href="#ch9-5">9.5 v2.2c vs v2.2d 对比</a></li>
<li><a href="#ch10"><span class="toc-num"></span> 策略演进史</a></li>
<li class="toc-sub"><a href="#ch10-1">10.1 v1.x 时代:试错与奠基</a></li>
<li class="toc-sub"><a href="#ch10-2">10.2 v2.x 时代:突破与优化</a></li>
<li class="toc-sub"><a href="#ch10-3">10.3 关键教训总结</a></li>
<li><a href="#ch11"><span class="toc-num">十一</span> 已知隐患与风险评估</a></li>
<li class="toc-sub"><a href="#ch11-1">11.1 策略层面风险</a></li>
<li class="toc-sub"><a href="#ch11-2">11.2 执行层面风险</a></li>
<li class="toc-sub"><a href="#ch11-3">11.3 外部不可控风险</a></li>
<li><a href="#ch12"><span class="toc-num">十二</span> 下一步优化方向</a></li>
<li class="toc-sub"><a href="#ch12-1">12.1 短期优化1-3个月</a></li>
<li class="toc-sub"><a href="#ch12-2">12.2 中期优化3-12个月</a></li>
<li class="toc-sub"><a href="#ch12-3">12.3 长期愿景</a></li>
<li><a href="#appendix"><span class="toc-num">附录</span></a></li>
<li class="toc-sub"><a href="#appendix-a">附录A完整参数表</a></li>
<li class="toc-sub"><a href="#appendix-b">附录B回测环境配置</a></li>
<li class="toc-sub"><a href="#appendix-c">附录C策略完整源码</a></li>
<li class="toc-sub"><a href="#appendix-d">附录D术语表</a></li>
</ol>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 1 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch1">
<h2><span class="ch-num">第一章</span>策略总览与设计哲学</h2>
<h3 id="ch1-1">1.1 策略定位</h3>
<p>Structure Flow Strategy v2.2d 是一套基于<strong>纯价格行为学Price Action</strong>的 ETH/USDT 永续合约中低频趋势跟踪策略。策略运行于 <strong>1 小时时间框架</strong>,辅以 4 小时和日线级别的宏观结构分析,日均交易 0.7 笔,持仓周期约 21.5 小时。</p>
<div class="metrics-grid">
<div class="metric-card blue"><div class="val">2057x</div><div class="lbl">总回报倍数</div></div>
<div class="metric-card green"><div class="val">309%</div><div class="lbl">年化 CAGR</div></div>
<div class="metric-card"><div class="val">1.03</div><div class="lbl">Sharpe 比率</div></div>
<div class="metric-card"><div class="val">1,375</div><div class="lbl">总交易笔数</div></div>
<div class="metric-card red"><div class="val">28.9%</div><div class="lbl">胜率</div></div>
<div class="metric-card"><div class="val">20.58%</div><div class="lbl">最大回撤</div></div>
</div>
<div class="table-note" style="text-align:center">回测区间2021-01-01 至 2026-06-01约5.5年)· 初始资金 $10,000 · 最终资金 $20,578,435</div>
<div class="highlight">
<strong>核心定位一句话:</strong>在日线趋势方向上的 1H 支撑/阻力位,等待价格结构确认后入场,通过动态追踪止损让利润奔跑,同时在结构破坏时果断止损。
</div>
<h3 id="ch1-2">1.2 设计哲学:纯价格行为学</h3>
<p>v2.2d 不依赖任何传统技术指标——没有 EMA、没有 MACD、没有 RSI、没有布林带。策略的"眼睛"只有三个东西:</p>
<ol>
<li><strong>Swing Points摆动高低点</strong>——市场留下的足迹,多空博弈的历史胜负记录</li>
<li><strong>Support / Resistance支撑 / 阻力)</strong>——最近的有效 Swing Point买卖双方曾在此达成共识的位置</li>
<li><strong>Candle PatternsK 线形态)</strong>——Pin Bar锤子线/流星线)和 Engulfing吞没形态当前博弈的实时裁判</li>
</ol>
<div class="highlight">
<strong>为什么纯价格行为学?</strong><br><br>
所有技术指标都是价格的衍生品。EMA 是价格的滞后平均RSI 是价格的归一化处理。当市场微观结构发生变化——波动率变了、流动性结构变了、参与者构成变了——EMA 和 RSI 的最佳参数也跟着变了。但一根 Pin Bar 还是一根 Pin Bar一个假突破还是一个假突破。<br><br>
因为底层是<strong>人性的贪婪和恐惧</strong>,而人性在可预见的未来不会改变。
</div>
<h3 id="ch1-3">1.3 第一性原理</h3>
<p>v2.2d 的逻辑可以拆解为四个第一性原理:</p>
<table>
<tr><th style="width:22%">原理</th><th>表述</th><th style="width:28%">在策略中的映射</th></tr>
<tr>
<td><strong>顺势而为</strong></td>
<td>趋势是你的朋友。反转大部分失败,顺势交易的概率优势是压倒性的。</td>
<td>D1 趋势向上才做多D1 趋势向下才做空。4H 趋势强度确认。</td>
</tr>
<tr>
<td><strong>S/R 位入场</strong></td>
<td>支撑和阻力是市场记忆的锚点。价格在这些位置的反应提供了低风险的入场时机。</td>
<td>供需区域Demand/Supply Zone+ 活支撑/阻力Alive S/R双重过滤。</td>
</tr>
<tr>
<td><strong>让利润奔跑</strong></td>
<td>交易的利润不来自胜率,而来自少数大赢家。截断亏损容易,让利润奔跑难。</td>
<td>动态追踪止损Trailing Stop Loss。亏损单平均持仓 9 小时,盈利单平均持仓 2 天 3 小时。</td>
</tr>
<tr>
<td><strong>纪律优于预测</strong></td>
<td>不要试图预测下一根 K 线。策略的工作是"如果 A 则 B",不是"我认为会涨"。</td>
<td>6 项入场条件全部为布尔值,无模糊判断。冷却期防止情绪化追单。</td>
</tr>
</table>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 2 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch2">
<h2><span class="ch-num">第二章</span>系统架构与数据流</h2>
<h3 id="ch2-1">2.1 多时间框架架构</h3>
<p>v2.2d 采用<strong>三层时间框架</strong>结构,自上而下形成"宏观定方向 → 中观定趋势 → 微观定入场"的决策链条:</p>
<div class="figure">
<svg viewBox="0 0 680 300" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gD1" x1="0" y1="0" x2="1" y2="0"><stop offset="0%" stop-color="#1e3a5f"/><stop offset="100%" stop-color="#2563eb"/></linearGradient>
<linearGradient id="g4H" x1="0" y1="0" x2="1" y2="0"><stop offset="0%" stop-color="#3b82f6"/><stop offset="100%" stop-color="#60a5fa"/></linearGradient>
<linearGradient id="g1H" x1="0" y1="0" x2="1" y2="0"><stop offset="0%" stop-color="#60a5fa"/><stop offset="100%" stop-color="#93c5fd"/></linearGradient>
</defs>
<!-- D1 -->
<rect x="40" y="30" width="600" height="68" rx="6" fill="url(#gD1)" opacity="0.95"/>
<text x="70" y="58" fill="#fff" font-size="16" font-weight="700">D1 日线</text>
<text x="70" y="80" fill="#bfdbfe" font-size="11">Swing Point 检测lookback=10→ 趋势方向判定trend_up / trend_down</text>
<text x="600" y="58" fill="#93c5fd" font-size="10" text-anchor="end">@informative("1d")</text>
<!-- Arrow D1 -> 4H -->
<line x1="340" y1="98" x2="340" y2="120" stroke="#94a3b8" stroke-width="1.5" marker-end="url(#arrowGray)"/>
<defs><marker id="arrowGray" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto"><path d="M0,0 L8,3 L0,6 Z" fill="#94a3b8"/></marker></defs>
<!-- 4H -->
<rect x="40" y="122" width="600" height="68" rx="6" fill="url(#g4H)" opacity="0.95"/>
<text x="70" y="150" fill="#fff" font-size="16" font-weight="700">4H 四小时</text>
<text x="70" y="172" fill="#dbeafe" font-size="11">Swing Point 检测lookback=8→ 趋势强度 quantile → strong_uptrend / strong_downtrend</text>
<text x="600" y="150" fill="#bfdbfe" font-size="10" text-anchor="end">@informative("4h")</text>
<!-- Arrow 4H -> 1H -->
<line x1="340" y1="190" x2="340" y2="212" stroke="#94a3b8" stroke-width="1.5" marker-end="url(#arrowGray)"/>
<!-- 1H -->
<rect x="40" y="214" width="600" height="68" rx="6" fill="url(#g1H)" opacity="0.95"/>
<text x="70" y="242" fill="#fff" font-size="16" font-weight="700">1H 一小时 · 主时间框架</text>
<text x="70" y="264" fill="#eff6ff" font-size="11">Swing Pointlookback=5→ S/R 结构 + 供需区域 + K线形态 + 活S/R + 入场信号生成</text>
<text x="600" y="242" fill="#dbeafe" font-size="10" text-anchor="end">populate_indicators()</text>
</svg>
<div class="figure-caption">图 2-1v2.2d 三层时间框架架构。D1 定方向4H 算强度1H 做执行。</div>
</div>
<p><strong>D1日线</strong>使用 <code>@informative("1d")</code> 装饰器,在日线级别检测 Swing Point 并判断趋势方向(<code>trend_up</code> / <code>trend_down</code>)。这是策略的"宪法"——D1 趋势决定允许做多还是做空。</p>
<p><strong>4H四小时</strong>使用 <code>@informative("4h")</code> 装饰器。不仅判断趋势方向,还计算<strong>趋势强度</strong>。趋势强度的算法是:最近两个 Swing High 的间距变化率 + 最近两个 Swing Low 的间距变化率。强度 > <code>trend_strength_min</code>(默认 -0.20,即 -20%)则标记为强势趋势。</p>
<p><strong>1H一小时</strong>主时间框架。在此层级完成所有核心计算Swing Point 检测、S/R 结构分析、供需区域划分、K 线形态识别、活支撑/阻力判定、入场信号生成和冷却期应用。</p>
<h3 id="ch2-2">2.2 数据处理流程</h3>
<div class="figure">
<svg viewBox="0 0 680 380" xmlns="http://www.w3.org/2000/svg">
<rect x="15" y="10" width="160" height="40" rx="5" fill="#1e3a5f"/>
<text x="95" y="36" fill="#fff" font-size="12" text-anchor="middle" font-weight="600">原始 OHLCV</text>
<line x1="95" y1="50" x2="95" y2="68" stroke="#64748b" stroke-width="1.5" marker-end="url(#arr2)"/>
<defs><marker id="arr2" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto"><path d="M0,0 L8,3 L0,6 Z" fill="#64748b"/></marker></defs>
<rect x="15" y="70" width="160" height="40" rx="5" fill="#1e40af"/>
<text x="95" y="90" fill="#fff" font-size="11" text-anchor="middle">populate_indicators_1d</text>
<text x="95" y="104" fill="#93c5fd" font-size="9" text-anchor="middle">Swing + 趋势方向</text>
<rect x="195" y="70" width="160" height="40" rx="5" fill="#2563eb"/>
<text x="275" y="90" fill="#fff" font-size="11" text-anchor="middle">populate_indicators_4h</text>
<text x="275" y="104" fill="#93c5fd" font-size="9" text-anchor="middle">Swing + 趋势强度</text>
<line x1="95" y1="110" x2="95" y2="128" stroke="#64748b" stroke-width="1.5" marker-end="url(#arr2)"/>
<line x1="275" y1="110" x2="275" y2="128" stroke="#64748b" stroke-width="1.5" marker-end="url(#arr2)"/>
<line x1="175" y1="90" x2="195" y2="90" stroke="#64748b" stroke-width="1" stroke-dasharray="4,3"/>
<rect x="15" y="130" width="340" height="50" rx="5" fill="#3b82f6"/>
<text x="185" y="152" fill="#fff" font-size="12" text-anchor="middle" font-weight="600">populate_indicators (1H 主框架)</text>
<text x="185" y="170" fill="#dbeafe" font-size="9" text-anchor="middle">Swing(1H) → S/R结构 → 供需区域 → K线形态 → 活S/R</text>
<line x1="185" y1="180" x2="185" y2="200" stroke="#64748b" stroke-width="1.5" marker-end="url(#arr2)"/>
<rect x="15" y="202" width="160" height="40" rx="5" fill="#0891b2"/>
<text x="95" y="222" fill="#fff" font-size="11" text-anchor="middle">populate_entry_trend</text>
<text x="95" y="236" fill="#cffafe" font-size="9" text-anchor="middle">6项条件 + 冷却期</text>
<rect x="195" y="202" width="160" height="40" rx="5" fill="#0e7490"/>
<text x="275" y="222" fill="#fff" font-size="11" text-anchor="middle">populate_exit_trend</text>
<text x="275" y="236" fill="#cffafe" font-size="9" text-anchor="middle">D1结构出场</text>
<line x1="95" y1="242" x2="95" y2="262" stroke="#64748b" stroke-width="1.5" marker-end="url(#arr2)"/>
<line x1="275" y1="242" x2="275" y2="262" stroke="#64748b" stroke-width="1.5" marker-end="url(#arr2)"/>
<rect x="15" y="264" width="340" height="40" rx="5" fill="#0f172a"/>
<text x="185" y="284" fill="#fff" font-size="12" text-anchor="middle" font-weight="600">Freqtrade 回测/实盘引擎</text>
<text x="185" y="298" fill="#94a3b8" font-size="9" text-anchor="middle">订单执行 · custom_stoploss · 资金管理</text>
<line x1="185" y1="304" x2="185" y2="322" stroke="#64748b" stroke-width="1.5" marker-end="url(#arr2)"/>
<rect x="65" y="324" width="240" height="40" rx="20" fill="#16a34a"/>
<text x="185" y="350" fill="#fff" font-size="12" text-anchor="middle" font-weight="600">交易执行 &amp; 盈亏记录</text>
</svg>
<div class="figure-caption">图 2-2v2.2d 数据处理流程。D1 和 4H 作为信息时间框架并行计算1H 主框架汇总后生成信号。</div>
</div>
<h3 id="ch2-3">2.3 参数一览</h3>
<table>
<tr><th style="width:25%">参数名</th><th style="width:12%">默认值</th><th style="width:15%">可调范围</th><th>说明</th></tr>
<tr><td><code>swing_lookback_d1</code></td><td>10</td><td>8 ~ 14</td><td>D1 Swing Point 检测窗口。越大越滞后,越小越敏感。</td></tr>
<tr><td><code>swing_lookback_h4</code></td><td>8</td><td>5 ~ 10</td><td>4H Swing Point 检测窗口。用于趋势强度计算。</td></tr>
<tr><td><code>swing_lookback_1h</code></td><td>5</td><td>3 ~ 7</td><td>1H Swing Point 检测窗口。直接决定 S/R 位置。</td></tr>
<tr><td><code>pin_bar_wick_ratio</code></td><td>60%</td><td>50 ~ 70%</td><td>Pin Bar 识别阈值。影线占比需 > 此值。</td></tr>
<tr><td><code>max_stop_dist</code></td><td>50%</td><td>20 ~ 50%</td><td>入场时价格与 S/R 的最大距离(%)。限制止损成本。</td></tr>
<tr><td><code>cooldown_bars</code></td><td>6</td><td>3 ~ 12</td><td>入场后冷却 K 线数。防止连续追单。</td></tr>
<tr><td><code>trend_strength_min</code></td><td>-20%</td><td>-50 ~ +20%</td><td>4H 趋势强度最低阈值。负值=允许弱趋势入场。</td></tr>
</table>
<div class="highlight highlight-amber">
<strong>参数设计原则:</strong>7 个可调参数全部是 IntParameter整数在回测中可通过 Hyperopt 自动优化。<code>trend_strength_min</code> 设为 -20% 意味着策略在非常宽松的条件下也允许入场——历史回测表明,过度收紧此参数会误杀大量盈利交易。
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 3 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch3">
<h2><span class="ch-num">第三章</span>核心组件:价格结构识别</h2>
<h3 id="ch3-1">3.1 Swing Point 检测算法</h3>
<p>Swing Point 是价格行为学的基石。一个 Swing High 被定义为:<strong>某个 K 线的高点,比它左右各 N 根 K 线的高点都高。</strong>Swing Low 同理。</p>
<pre><code>def _detect_swing_points(high, low, window=5):
n = len(high)
sh = pd.Series(np.nan, index=high.index)
sl = pd.Series(np.nan, index=low.index)
for i in range(window, n - window):
# Swing High: 当前高点 > 左 window 根和右 window 根的所有高点
if (high.iloc[i] > high.iloc[i-window:i].max() and
high.iloc[i] > high.iloc[i+1:i+window+1].max()):
sh.iloc[i] = high.iloc[i]
# Swing Low: 当前低点 < window 根和右 window 根的所有低点
if (low.iloc[i] < low.iloc[i-window:i].min() and
low.iloc[i] < low.iloc[i+1:i+window+1].min()):
sl.iloc[i] = low.iloc[i]
return sh, sl</code></pre>
<div class="highlight">
<strong>算法特性:</strong><br>
① 使用 <strong>严格大于/小于</strong>,不包含等于——只有真正的极值点才会被标记。<br>
② 左右对称窗口——确保了"现在"不会偏见地偏向任何一侧。<br>
③ 非 Swing Point 位置填 NaN——后续结构分析中逐 K 线遍历时通过 <code>pd.notna()</code> 判断。
</div>
<div class="figure">
<svg viewBox="0 0 680 220" xmlns="http://www.w3.org/2000/svg">
<!-- Example price line with swing points -->
<polyline points="30,180 80,140 130,170 180,120 230,160 280,130 330,150 380,110 430,145 480,125 530,155 580,135 630,160" fill="none" stroke="#64748b" stroke-width="1.5"/>
<!-- Swing High markers -->
<circle cx="180" cy="120" r="4" fill="#ef4444"/>
<text x="180" y="110" fill="#ef4444" font-size="9" text-anchor="middle">SH</text>
<circle cx="380" cy="110" r="4" fill="#ef4444"/>
<text x="380" y="100" fill="#ef4444" font-size="9" text-anchor="middle">SH</text>
<!-- Swing Low markers -->
<circle cx="130" cy="170" r="4" fill="#22c55e"/>
<text x="130" y="188" fill="#22c55e" font-size="9" text-anchor="middle">SL</text>
<circle cx="280" cy="130" r="4" fill="#22c55e"/>
<text x="280" y="148" fill="#22c55e" font-size="9" text-anchor="middle">SL</text>
<circle cx="480" cy="125" r="4" fill="#22c55e"/>
<text x="480" y="143" fill="#22c55e" font-size="9" text-anchor="middle">SL</text>
<!-- Window illustration -->
<rect x="100" y="74" width="160" height="100" fill="none" stroke="#3b82f6" stroke-width="1" stroke-dasharray="5,3" rx="3"/>
<text x="180" y="70" fill="#3b82f6" font-size="9" text-anchor="middle">window=5 检测窗口</text>
<!-- Axis -->
<line x1="20" y1="185" x2="650" y2="185" stroke="#1a1a1a" stroke-width="1"/>
</svg>
<div class="figure-caption">图 3-1Swing Point 检测示意。红色圆= Swing High绿色圆= Swing Low。虚线框为 window=5 的检测范围。</div>
</div>
<h3 id="ch3-2">3.2 结构分析:趋势判断与 S/R 定位</h3>
<p><code>_build_structure()</code> 是策略最核心的函数。它逐 K 线遍历,维护最近 4 个 Swing High 和 Swing Low 的列表,并实时判断:</p>
<ol>
<li><strong>趋势方向Trend Up / Trend Down</strong>如果最近两个 Swing High 依次抬高 <strong></strong> 最近两个 Swing Low 依次抬高 → 上升趋势。反之则下降趋势。两者都不满足时,继承上一根 K 线的趋势判断。</li>
<li><strong>支撑/阻力位:</strong>最近一个 Swing Low 的价格 = 支撑位Support最近一个 Swing High 的价格 = 阻力位Resistance</li>
<li><strong>供需区域:</strong>在支撑和阻力之间,计算当前价格的位置百分比。百分比 &lt; 35% 为需求区Demand Zone百分比 &gt; 65% 为供给区Supply Zone</li>
</ol>
<div class="highlight">
<strong>趋势继承原则:</strong>当 Swing Point 不足时(比如策略启动初期或长时间无新高/新低),趋势判断<strong>不会</strong>变成"无趋势"或"未知"——它会继承上一根 K 线的判断。这确保了策略不会在数据不足时"失明",而是保守地保持上一状态。
</div>
<h3 id="ch3-3">3.3 供需区域划分</h3>
<div class="figure">
<svg viewBox="0 0 680 260" xmlns="http://www.w3.org/2000/svg">
<!-- Zone visualization -->
<rect x="80" y="40" width="520" height="200" fill="#f8f9fb" stroke="#e5e7eb" stroke-width="1" rx="4"/>
<!-- Resistance line -->
<line x1="60" y1="55" x2="620" y2="55" stroke="#ef4444" stroke-width="2" stroke-dasharray="8,4"/>
<text x="630" y="59" fill="#ef4444" font-size="11" font-weight="600">Resistance = 最近 SH</text>
<!-- Supply zone (65%-100%) -->
<rect x="80" y="55" width="520" height="55" fill="#fef2f2" opacity="0.8"/>
<text x="340" y="86" fill="#dc2626" font-size="12" text-anchor="middle" font-weight="600">供给区 Supply Zone (65%~100%)</text>
<text x="340" y="100" fill="#ef4444" font-size="10" text-anchor="middle">做空入场区域</text>
<!-- Mid zone -->
<rect x="80" y="110" width="520" height="60" fill="#f8fafc" opacity="0.8"/>
<text x="340" y="144" fill="#94a3b8" font-size="12" text-anchor="middle">中间区域 (35%~65%) — 不交易</text>
<!-- Demand zone (0%-35%) -->
<rect x="80" y="170" width="520" height="55" fill="#f0fdf4" opacity="0.8"/>
<text x="340" y="200" fill="#16a34a" font-size="12" text-anchor="middle" font-weight="600">需求区 Demand Zone (0%~35%)</text>
<text x="340" y="214" fill="#22c55e" font-size="10" text-anchor="middle">做多入场区域</text>
<!-- Support line -->
<line x1="60" y1="240" x2="620" y2="240" stroke="#22c55e" stroke-width="2" stroke-dasharray="8,4"/>
<text x="630" y="244" fill="#22c55e" font-size="11" font-weight="600">Support = 最近 SL</text>
<!-- Position marker -->
<text x="40" y="158" fill="#64748b" font-size="10">价格</text>
<line x1="70" y1="155" x2="80" y2="155" stroke="#64748b" stroke-width="1"/>
</svg>
<div class="figure-caption">图 3-2供需区域划分。当价格处于最近支撑和阻力之间的下 35% 区域时触发做多条件,上 35%(即 65%~100%)时触发做空条件。中间区域不交易。</div>
</div>
<h3>3.4 活支撑/阻力Support/Resistance Alive</h3>
<p>这是策略中最精妙的条件之一。仅仅"存在"支撑/阻力是不够的——策略要求这个 S/R 是<strong>活的</strong>:它在最近的 3 根 K 线内被测试过,并且<strong>守住了</strong></p>
<pre><code># 活支撑价格触及支撑±0.5%)且收盘在支撑上方
touched_support = (
(low <= support * 1.005) & (low >= support * 0.995)
)
held_support = close > support
support_tested_and_held = touched_support & held_support
support_alive = support_tested_and_held.rolling(3, min_periods=1).max() > 0</code></pre>
<div class="highlight highlight-green">
<strong>为什么需要这个条件?</strong> 一个 50 根 K 线前形成的支撑位,市场可能已经完全忘记它了。但如果价格在最近 3 小时内刚刚测试过这个位置并守住了——那它是"活的",市场参与者确实在参考它。<br><br>
<strong>2026-06-11 14:00 实盘验证:</strong>1H Swing High 在 166111:00 K线之后价格接近但未重新测试。到 14:00 时窗口过期3根K线<code>resistance_alive</code> 从 True 变 False策略正确拒单。说明这个条件在实战中确实在履行"最后一道关"的职责。
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 4 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch4">
<h2><span class="ch-num">第四章</span>核心组件K线形态识别</h2>
<h3 id="ch4-1">4.1 Pin Bar 检测</h3>
<p>Pin Bar也称为锤子线/流星线/十字星)是价格行为学中最重要的单 K 线反转信号。其核心特征是:<strong>影线wick极长实体body极短。</strong></p>
<pre><code>body = abs(close - open)
total_range = (high - low).replace(0, 0.0001)
upper_wick = high - max(open, close)
lower_wick = min(open, close) - low
# Pin Bar 条件:影线占总范围的 60% 以上
is_pin = (upper_wick + lower_wick) / total_range > 0.6
# 看涨 Pin Bar阳线 + 下影线 > 上影线(买方在低位强力反击)
bullish_pin = is_pin & (close > open) & (lower_wick > upper_wick)
# 看跌 Pin Bar阴线 + 上影线 > 下影线(卖方在高位强力压制)
bearish_pin = is_pin & (close < open) & (upper_wick > lower_wick)</code></pre>
<div class="figure">
<svg viewBox="0 0 400 180" xmlns="http://www.w3.org/2000/svg">
<!-- Bullish Pin Bar -->
<text x="130" y="18" fill="#16a34a" font-size="12" text-anchor="middle" font-weight="600">看涨 Pin Bar</text>
<line x1="130" y1="25" x2="130" y2="140" stroke="#16a34a" stroke-width="1.5"/>
<rect x="115" y="110" width="30" height="20" fill="#16a34a" rx="2"/>
<text x="130" y="160" fill="#64748b" font-size="9" text-anchor="middle">影线 70%</text>
<!-- Bearish Pin Bar -->
<text x="270" y="18" fill="#ef4444" font-size="12" text-anchor="middle" font-weight="600">看跌 Pin Bar</text>
<line x1="270" y1="25" x2="270" y2="140" stroke="#ef4444" stroke-width="1.5"/>
<rect x="255" y="35" width="30" height="20" fill="#ef4444" rx="2"/>
<text x="270" y="160" fill="#64748b" font-size="9" text-anchor="middle">影线 70%</text>
</svg>
<div class="figure-caption">图 4-1Pin Bar 形态示意。左为看涨(长下影+阳线),右为看跌(长上影+阴线)。</div>
</div>
<h3 id="ch4-2">4.2 吞没形态检测</h3>
<p>吞没形态Engulfing是两K线组合形态也是价格行为学中可信度最高的反转信号之一。</p>
<pre><code>prev_open = open.shift(1)
prev_close = close.shift(1)
# 看涨吞没:当前阳线完全吞没前一根阴线
bullish_engulf = (
(close > prev_open) & (open < prev_close) & (close > open)
)
# 看跌吞没:当前阴线完全吞没前一根阳线
bearish_engulf = (
(close < prev_open) & (open > prev_close) & (close < open)
)</code></pre>
<h3 id="ch4-3">4.3 形态在策略中的角色</h3>
<p>在 v2.2d 中K 线形态虽然在代码中被计算(<code>bullish_pinbar</code><code>bearish_pinbar</code><code>bullish_engulfing</code><code>bearish_engulfing</code>),但在当前的入场条件中<strong>并未被直接使用</strong>。策略选择用供需区域 + 活 S/R 替代了 K 线形态确认。</p>
<div class="highlight highlight-amber">
<strong>为什么没用到?</strong> 在 v2.2c → v2.2d 的演进中入场条件经历了多次精简。K 线形态曾在前代版本中被使用,但回测发现:供需区域这个条件本身就足够强大——当价格已经处于需求区且支撑位是活的时,额外的形态过滤只会降低入场频率而不显著提升胜率。<br><br>
形态检测代码保留在策略中用于 <code>plot_config</code> 可视化,方便实盘监控时观察。
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 5 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch5">
<h2><span class="ch-num">第五章</span>入场条件详解</h2>
<h3 id="ch5-1">5.1 做多入场6项条件</h3>
<p>所有 6 项条件必须同时满足,策略才会发出做多信号:</p>
<table>
<tr><th style="width:5%">#</th><th style="width:18%">条件</th><th style="width:12%">代码变量</th><th>逻辑</th></tr>
<tr>
<td>1</td><td><strong>D1 上升趋势</strong></td><td><code>trend_up_1d</code></td>
<td>日线级别 Swing High 和 Swing Low 依次抬高。这是"顺势"的根保证。</td>
</tr>
<tr>
<td>2</td><td><strong>价格处于需求区</strong></td><td><code>in_demand</code></td>
<td>当前收盘价在支撑-阻力区间的下 35% 内。确保入场位置有足够的上涨空间。</td>
</tr>
<tr>
<td>3</td><td><strong>止损距离合理</strong></td><td><code>long_stop_dist &lt;= max_stop_dist</code></td>
<td>入场价距支撑位不超过 50%(默认),且必须 > 0.3%。防止止损太远或太近。</td>
</tr>
<tr>
<td>4</td><td><strong>支撑位有效</strong></td><td><code>support_alive</code></td>
<td>最近 3 根 K 线内价格曾测试支撑并收盘在其上方。证明市场"记得"这个位置。</td>
</tr>
<tr>
<td>5</td><td><strong>4H 强势上升</strong></td><td><code>strong_uptrend_4h</code></td>
<td>4H 级别趋势强度 > -20%。中观级别确认趋势有效性,过滤假突破。</td>
</tr>
<tr>
<td>6</td><td><strong>冷却期已过</strong></td><td><code>_apply_cooldown()</code></td>
<td>距离上次入场已超过 6 根 K 线(默认)。防止连续追单和过度交易。</td>
</tr>
</table>
<h3 id="ch5-2">5.2 做空入场6项条件</h3>
<table>
<tr><th style="width:5%">#</th><th style="width:18%">条件</th><th style="width:12%">代码变量</th><th>逻辑</th></tr>
<tr>
<td>1</td><td><strong>D1 下降趋势</strong></td><td><code>trend_down_1d</code></td>
<td>日线级别 Swing High 和 Swing Low 依次降低。</td>
</tr>
<tr>
<td>2</td><td><strong>价格处于供给区</strong></td><td><code>in_supply</code></td>
<td>当前收盘价在支撑-阻力区间的上 35%(即 65%~100%)。</td>
</tr>
<tr>
<td>3</td><td><strong>止损距离合理</strong></td><td><code>short_stop_dist &lt;= max_stop_dist</code></td>
<td>阻力位距入场价不超过 50%,且必须 > 0.3%。</td>
</tr>
<tr>
<td>4</td><td><strong>阻力位有效</strong></td><td><code>resistance_alive</code></td>
<td>最近 3 根 K 线内价格曾测试阻力并收盘在其下方。</td>
</tr>
<tr>
<td>5</td><td><strong>4H 强势下降</strong></td><td><code>strong_downtrend_4h</code></td>
<td>4H 级别下降趋势强度 > -20%。</td>
</tr>
<tr>
<td>6</td><td><strong>冷却期已过</strong></td><td><code>_apply_cooldown()</code></td>
<td>距离上次入场已超过 6 根 K 线。</td>
</tr>
</table>
<div class="highlight highlight-amber">
<strong>止损距离下限 0.3%</strong>这个微小的门槛有一个重要功能——防止在 S/R 位"紧贴"价格时入场。如果入场价距离支撑/阻力只有 0.3% 以内,说明价格几乎就在 S/R 位上,一根正常的 K 线波动就能穿透它。这个门槛确保了每笔交易都有"呼吸空间"。
</div>
<h3 id="ch5-3">5.3 入场决策流程图</h3>
<div class="figure">
<svg viewBox="0 0 680 520" xmlns="http://www.w3.org/2000/svg">
<rect x="240" y="10" width="200" height="36" rx="18" fill="#1e3a5f"/>
<text x="340" y="33" fill="#fff" font-size="13" text-anchor="middle" font-weight="600">每根 1H K 线</text>
<line x1="340" y1="46" x2="340" y2="60" stroke="#64748b" stroke-width="1.5" marker-end="url(#a3)"/>
<defs><marker id="a3" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto"><path d="M0,0 L8,3 L0,6 Z" fill="#64748b"/></marker></defs>
<!-- Diamond: D1 trend? -->
<polygon points="340,62 440,100 340,138 240,100" fill="#eff6ff" stroke="#3b82f6" stroke-width="1.5"/>
<text x="340" y="98" fill="#1e3a5f" font-size="10" text-anchor="middle">D1趋势方向?</text>
<line x1="440" y1="100" x2="500" y2="100" stroke="#64748b" stroke-width="1.5"/>
<text x="470" y="94" fill="#16a34a" font-size="9">上升</text>
<!-- Long branch -->
<rect x="500" y="82" width="150" height="36" rx="5" fill="#f0fdf4" stroke="#22c55e" stroke-width="1"/>
<text x="575" y="104" fill="#16a34a" font-size="10" text-anchor="middle">做多路径</text>
<line x1="575" y1="118" x2="575" y2="132" stroke="#64748b" stroke-width="1.5" marker-end="url(#a3)"/>
<polygon points="575,134 650,160 575,186 500,160" fill="#fff" stroke="#3b82f6" stroke-width="1"/>
<text x="575" y="158" fill="#1a1a1a" font-size="9" text-anchor="middle">in_demand ?</text>
<line x1="650" y1="160" x2="660" y2="160" stroke="#16a34a" stroke-width="1.5"/>
<text x="655" y="155" fill="#16a34a" font-size="8">Y</text>
<rect x="580" y="188" width="100" height="28" rx="4" fill="#f0fdf4" stroke="#22c55e" stroke-width="1"/>
<text x="630" y="206" fill="#16a34a" font-size="9" text-anchor="middle">stop_dist OK?</text>
<line x1="630" y1="216" x2="630" y2="230" stroke="#64748b" stroke-width="1.5" marker-end="url(#a3)"/>
<rect x="580" y="232" width="100" height="28" rx="4" fill="#f0fdf4" stroke="#22c55e" stroke-width="1"/>
<text x="630" y="250" fill="#16a34a" font-size="9" text-anchor="middle">support_alive?</text>
<line x1="630" y1="260" x2="630" y2="274" stroke="#64748b" stroke-width="1.5" marker-end="url(#a3)"/>
<rect x="580" y="276" width="100" height="28" rx="4" fill="#f0fdf4" stroke="#22c55e" stroke-width="1"/>
<text x="630" y="294" fill="#16a34a" font-size="9" text-anchor="middle">4H strong?</text>
<line x1="630" y1="304" x2="630" y2="318" stroke="#64748b" stroke-width="1.5" marker-end="url(#a3)"/>
<rect x="580" y="320" width="100" height="28" rx="4" fill="#f0fdf4" stroke="#22c55e" stroke-width="1"/>
<text x="630" y="338" fill="#16a34a" font-size="9" text-anchor="middle">冷却期已过?</text>
<line x1="630" y1="348" x2="630" y2="370" stroke="#16a34a" stroke-width="2" marker-end="url(#a3)"/>
<rect x="555" y="372" width="150" height="40" rx="20" fill="#16a34a"/>
<text x="630" y="398" fill="#fff" font-size="12" text-anchor="middle" font-weight="600">✅ ENTER LONG</text>
<!-- Short branch -->
<line x1="340" y1="138" x2="340" y2="160" stroke="#64748b" stroke-width="1.5"/>
<text x="310" y="155" fill="#ef4444" font-size="9">下降</text>
<rect x="265" y="162" width="150" height="36" rx="5" fill="#fef2f2" stroke="#ef4444" stroke-width="1"/>
<text x="340" y="184" fill="#dc2626" font-size="10" text-anchor="middle">做空路径</text>
<text x="340" y="220" fill="#94a3b8" font-size="9" text-anchor="middle">... 对称的 6 项检查</text>
<line x1="340" y1="232" x2="340" y2="260" stroke="#dc2626" stroke-width="2" marker-end="url(#a3)"/>
<rect x="265" y="262" width="150" height="40" rx="20" fill="#dc2626"/>
<text x="340" y="288" fill="#fff" font-size="12" text-anchor="middle" font-weight="600">✅ ENTER SHORT</text>
<!-- Neither branch -->
<line x1="240" y1="100" x2="160" y2="100" stroke="#64748b" stroke-width="1.5"/>
<text x="200" y="94" fill="#94a3b8" font-size="9">无/震荡</text>
<rect x="60" y="82" width="100" height="36" rx="5" fill="#f1f5f9" stroke="#94a3b8" stroke-width="1"/>
<text x="110" y="104" fill="#64748b" font-size="10" text-anchor="middle">空仓等待</text>
</svg>
<div class="figure-caption">图 5-1入场决策流程。D1 趋势方向决定做多/做空路径,随后依次检查 6 项条件。任何一项不满足即空仓。</div>
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 6 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch6">
<h2><span class="ch-num">第六章</span>冷却期机制v2.2c → v2.2d 关键修复</h2>
<h3 id="ch6-1">6.1 v2.2c 的致命 Bug</h3>
<p>v2.2c 使用了一个看似巧妙但实际有致命缺陷的冷却期实现:</p>
<pre><code># v2.2c 的 bug 实现
long_base = (...) # 6项条件布尔 Series
long_entries = long_base & (long_base.rolling(cooldown).max().shift(1) == 0)</code></pre>
<p><strong>Bug 的逻辑:</strong><code>rolling(cooldown).max()</code> 检测的是"过去 6 根 K 线中是否<strong>有任何一根满足条件</strong>"——而不是"过去 6 根 K 线中是否<strong>实际入场了</strong>"。</p>
<div class="highlight highlight-red">
<strong>致命场景:</strong>市场持续满足入场条件(例如 ETH 在强下降趋势中持续位于供给区,阻力位反复测试有效),那么 <code>rolling(6).max()</code> 永远为 True冷却期永远不解除。<br><br>
结果:策略在应该连续入场(每 6 根 K 线一次的市场中完全停止交易。这在回测中表现为交易次数偏少1056 vs 1375少了 30%)。
</div>
<h3 id="ch6-2">6.2 v2.2d 修复方案</h3>
<p>v2.2d 引入了一个全新的 <code>_apply_cooldown()</code> 方法,基于<strong>实际入场事件</strong>而非条件满足:</p>
<pre><code>def _apply_cooldown(self, signal: pd.Series, cooldown_bars: int) -> pd.Series:
"""
正确应用冷却期:入场后才冷却,而非条件满足就冷却。
"""
n = len(signal)
result = [False] * n
last_entry = -99999 # 上次入场的 bar 索引
values = signal.values
for i in range(n):
if values[i] and (i - last_entry) > cooldown_bars:
result[i] = True
last_entry = i
return pd.Series(result, index=signal.index)</code></pre>
<div class="highlight highlight-green">
<strong>修复逻辑:</strong><br>
① 逐 K 线遍历,模拟"入场 → 冷却"过程。<br>
② 当条件满足 <strong></strong> 距离上次入场 > <code>cooldown_bars</code> → 允许入场。<br>
③ 入场后更新 <code>last_entry</code>,接下来 <code>cooldown_bars</code> 根 K 线内即使条件满足也不会再次入场。<br>
④ 条件不满足的 K 线<strong>不消耗冷却期</strong>——冷却期只在入场后有效。<br><br>
时间复杂度 O(n),对 ~47,000 根 1H K 线约几毫秒,不影响回测性能。
</div>
<h3 id="ch6-3">6.3 修复效果对比</h3>
<table>
<tr><th>指标</th><th>v2.2c (Bug)</th><th>v2.2d (修复)</th><th>变化</th></tr>
<tr><td>交易笔数</td><td>1,056</td><td>1,375</td><td class="metric-card green" style="padding:2px 8px">+319 (+30%)</td></tr>
<tr><td>最终资金</td><td>$11,983,254</td><td>$20,578,435</td><td class="metric-card green" style="padding:2px 8px">+71.7%</td></tr>
<tr><td>CAGR</td><td>270.15%</td><td>309.01%</td><td class="metric-card green" style="padding:2px 8px">+38.86pp</td></tr>
<tr><td>Sharpe</td><td>0.82</td><td>1.03</td><td class="metric-card green" style="padding:2px 8px">+0.21</td></tr>
<tr><td>最大回撤</td><td>17.96%</td><td>20.58%</td><td class="metric-card red" style="padding:2px 8px">+2.62pp</td></tr>
<tr><td>利润因子</td><td>1.97</td><td>1.92</td><td>-0.05</td></tr>
<tr><td>胜率</td><td>29.7%</td><td>28.9%</td><td>-0.8pp</td></tr>
</table>
<div class="highlight">
<strong>关键洞察:</strong>修复冷却期后,策略多了 319 笔交易,胜率微降 0.8pp,但最终资金增加了 71.7%。这说明 v2.2c 被冷却期 bug 阻止的那 319 笔交易中,包含了大量盈利机会。冷却期修复让策略"该赚的钱都赚到了"Sharpe 从 0.82 跃升至 1.03——首次突破 1.0 门槛。
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 7 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch7">
<h2><span class="ch-num">第七章</span>出场逻辑</h2>
<h3 id="ch7-1">7.1 结构出场信号</h3>
<p>v2.2d 使用 D1 级别的趋势反转作为结构出场信号:</p>
<pre><code># 做多出场D1 不再上升
exit_long = ~dataframe["trend_up_1d"].fillna(True)
# 做空出场D1 转为上升
exit_short = dataframe["trend_up_1d"].fillna(False)</code></pre>
<p>逻辑非常简洁D1 结构破坏 = 离场。做多时如果日线趋势从上升转为非上升,立即出场。做空时如果日线趋势转为上升,立即出场。</p>
<div class="highlight highlight-amber">
<strong>回测数据:</strong>在 1375 笔交易中,仅有 9 笔通过 <code>exit_signal</code> 出场88.9% 胜率),说明绝大多数交易是被动态止损管理而非 D1 结构出场信号终止的。
</div>
<h3 id="ch7-2">7.2 动态止损Custom Stoploss</h3>
<p>这是策略真正的核心出场机制。止损位置<strong>动态绑定到 1H 级别的 S/R 位</strong></p>
<pre><code>def custom_stoploss(self, pair, trade, current_time, current_rate,
current_profit, after_fill, **kwargs):
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
last = dataframe.iloc[-1]
if not trade.is_short:
# 做多:止损 = 支撑位 × 0.999(支撑下方 0.1%
support = last.get("support", np.nan)
sl_price = support * 0.999
sl_ratio = (sl_price / current_rate) - 1.0
return max(sl_ratio, -0.15) # 硬上限 15%
else:
# 做空:止损 = 阻力位 × 1.001(阻力上方 0.1%
resistance = last.get("resistance", np.nan)
sl_price = resistance * 1.001
sl_ratio = 1.0 - (sl_price / current_rate)
return min(sl_ratio, 0.15) # 硬上限 15%</code></pre>
<div class="highlight highlight-green">
<strong>动态止损的三重智慧:</strong><br>
<strong>S/R 绑定:</strong>止损不固定在入场价的某个百分比,而是跟随 1H 级别的支撑/阻力位。当新的 Swing Low 形成时,支撑位上移,止损自动收紧——这就是策略的"移动止损"能力。<br>
<strong>0.1% 缓冲:</strong>止损设在支撑下方 0.1%(阻力上方 0.1%),给价格一个"假突破"的容忍空间。<br>
<strong>±15% 硬上限:</strong>防止极端行情下止损距离失控。在最坏情况下,单笔亏损不超过 15%。
</div>
<h3 id="ch7-3">7.3 出场逻辑完整流程</h3>
<p>每根 1H K 线收盘时,策略按以下优先级检查出场:</p>
<ol>
<li><strong>D1 结构出场:</strong>D1 趋势方向反转 → 无条件离场</li>
<li><strong>动态止损:</strong>当前价格触及 S/R 外侧 0.1% 缓冲 → 触发止损</li>
<li><strong>硬止损:</strong>亏损达到 15% → 无条件离场(极少触发,因为动态止损通常在更早位置就已经激活)</li>
</ol>
<div class="metrics-grid">
<div class="metric-card green"><div class="val">588</div><div class="lbl">追踪止损出场</div></div>
<div class="metric-card red"><div class="val">777</div><div class="lbl">止损出场</div></div>
<div class="metric-card"><div class="val">9</div><div class="lbl">结构出场</div></div>
<div class="metric-card"><div class="val">66.2%</div><div class="lbl">追踪止损胜率</div></div>
<div class="metric-card red"><div class="val">0%</div><div class="lbl">止损胜率</div></div>
<div class="metric-card green"><div class="val">88.9%</div><div class="lbl">结构出场胜率</div></div>
</div>
<p><strong>出场逻辑的核心统计数据:</strong></p>
<ul>
<li>588 笔通过 <code>trailing_stop_loss</code> 出场,胜率 66.2%,贡献 +383,557% 的利润</li>
<li>777 笔通过 <code>stop_loss</code> 出场,胜率 0%,亏损 -181,597%</li>
<li>9 笔通过 <code>exit_signal</code> 出场,胜率 88.9%</li>
<li>盈利交易平均持仓 <strong>2 天 3 小时</strong>,亏损交易平均持仓 <strong>9 小时 22 分</strong></li>
</ul>
<div class="highlight">
<strong>"让利润奔跑"的数学证据:</strong>盈利交易的平均持仓是亏损交易的 <strong>5.4 倍</strong>。这正是策略的核心竞争力——不是预测对的多,而是在对的时候拿得住。
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 8 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch8">
<h2><span class="ch-num">第八章</span>风险管理</h2>
<h3 id="ch8-1">8.1 硬止损上限</h3>
<p>策略设置了 <code>stoploss = -0.15</code>15%)作为全局硬止损。但在实际运行中,这个硬止损几乎不会被触发,因为 <code>custom_stoploss</code> 的动态 S/R 止损通常在较小的亏损幅度就已经激活。硬止损的存在是<strong>安全网</strong>——防止 <code>custom_stoploss</code> 在极端行情下返回异常值。</p>
<h3 id="ch8-2">8.2 仓位控制</h3>
<table>
<tr><th>参数</th><th></th><th>含义</th></tr>
<tr><td><code>max_open_trades</code></td><td>1</td><td>同一时间最多持有 1 笔仓位</td></tr>
<tr><td><code>stake_amount</code></td><td>unlimited</td><td>每笔交易使用全部可用资金(全仓)</td></tr>
<tr><td>杠杆</td><td>1x</td><td>不使用杠杆</td></tr>
<tr><td>保证金模式</td><td>Cross全仓</td><td>所有仓位共享保证金池</td></tr>
</table>
<div class="highlight highlight-green">
<strong>1x 杠杆 + 全仓 = 无爆仓风险。</strong>这不仅是一个仓位决策,更是一个哲学选择——"为而不恃"(不依赖外部力量放大结果)。回测已经证明,在 1x 杠杆下策略可以实现 2057 倍回报。杠杆不是必需品,而是资金利用效率工具。在当前阶段,无杠杆运行消除了最致命的风险源。
</div>
<h3 id="ch8-3">8.3 最大回撤分析</h3>
<p>回测显示的最大回撤为 <strong>20.58%</strong>(约 $2,200,994发生在 2026-05-05 至 2026-05-23持续 17 天 15 小时。回撤起点资金 $22,490,086终点 $20,279,092。</p>
<p>需要注意:</p>
<ul>
<li><strong>回撤绝对值巨大($2.2M</strong>这是复利效应的另一面——本金大了之后,同样的百分比回撤对应更大的绝对金额</li>
<li><strong>连续亏损记录:</strong>最大连续亏损为 24 笔。在 28.9% 胜率下,连续 24 笔亏损在统计上是必然会发生的事件</li>
<li><strong>心理考验:</strong>实盘中经历连续 24 笔亏损而不干预策略,是对交易者纪律性的终极考验</li>
</ul>
<div class="highlight highlight-red">
<strong>⚠️ 实盘回撤可能更大:</strong>回测中的最大回撤 20.58% 是在完美执行下的结果。实盘中滑点、执行延迟、心理干扰等因素可能将回撤放大至 30-40%。策略使用者必须做好在某个阶段看到账户缩水 30%+ 的心理准备。
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 9 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch9">
<h2><span class="ch-num">第九章</span>回测结果完整分析</h2>
<h3 id="ch9-1">9.1 核心指标摘要</h3>
<table>
<tr><th style="width:30%">指标</th><th>数值</th><th>评级</th></tr>
<tr><td>回测区间</td><td>2021-01-01 → 2026-06-011,977 天)</td><td>覆盖完整牛熊周期 ✅</td></tr>
<tr><td>交易模式</td><td>Cross Futures合约</td><td></td></tr>
<tr><td>交易笔数</td><td>1,375日均 0.7 笔)</td><td>中低频 ✅</td></tr>
<tr><td>初始资金</td><td>$10,000</td><td></td></tr>
<tr><td>最终资金</td><td>$20,578,435.93</td><td></td></tr>
<tr><td>总回报率</td><td>+205,684.36%2057倍</td><td>🏆 卓越</td></tr>
<tr><td>CAGR</td><td>309.01%</td><td>🏆 卓越</td></tr>
<tr><td>Sharpe 比率</td><td>1.03</td><td>良好(>1.0</td></tr>
<tr><td>Sortino 比率</td><td>3.88</td><td>优秀(下行风险控制好)</td></tr>
<tr><td>Calmar 比率</td><td>20,310.16</td><td>极高(收益远超回撤)</td></tr>
<tr><td>利润因子</td><td>1.92</td><td>良好(>1.5</td></tr>
<tr><td>SQN</td><td>2.88</td><td>良好(>2.0</td></tr>
<tr><td>胜率</td><td>28.9%398 胜 / 977 负)</td><td>偏低但可控</td></tr>
<tr><td>最大回撤</td><td>20.58%$2,200,994</td><td>可控</td></tr>
<tr><td>Expectancy</td><td>$14,959 (Ratio: 0.65)</td><td>正期望 ✅</td></tr>
</table>
<h3 id="ch9-2">9.2 出场原因分布</h3>
<table>
<tr><th>出场原因</th><th>笔数</th><th>占比</th><th>胜率</th><th>总盈亏 USDT</th><th>平均持仓</th></tr>
<tr>
<td><code>trailing_stop_loss</code></td>
<td>588</td><td>42.8%</td><td style="color:#16a34a;font-weight:700">66.2%</td>
<td style="color:#16a34a">+38,355,746</td>
<td>1天 17:47</td>
</tr>
<tr>
<td><code>stop_loss</code></td>
<td>777</td><td>56.5%</td><td style="color:#dc2626;font-weight:700">0%</td>
<td style="color:#dc2626">-18,159,746</td>
<td>6:13</td>
</tr>
<tr>
<td><code>exit_signal</code></td>
<td>9</td><td>0.7%</td><td style="color:#16a34a;font-weight:700">88.9%</td>
<td style="color:#16a34a">+317,061</td>
<td>11:20</td>
</tr>
<tr>
<td><code>force_exit</code></td>
<td>1</td><td>0.1%</td><td style="color:#16a34a;font-weight:700">100%</td>
<td style="color:#16a34a">+55,374</td>
<td>4:00</td>
</tr>
</table>
<div class="highlight">
<strong>关键解读:</strong><br>
• 56.5% 的交易以止损结束——这是 28.9% 胜率的另一面<br>
• 但 42.8% 的追踪止损出场贡献了 <strong>正 3836 万</strong> 的利润,远超止损的 1816 万亏损<br>
• 追踪止损出场的平均利润为 <strong>+2.6%</strong>,止损出场的平均亏损为 <strong>-0.89%</strong>,盈亏比约 <strong>2.92:1</strong>
</div>
<h3 id="ch9-3">9.3 多空表现对比</h3>
<table>
<tr><th>指标</th><th>做多 (Long)</th><th>做空 (Short)</th></tr>
<tr><td>交易笔数</td><td>748</td><td>627</td></tr>
<tr><td>总利润 USDT</td><td>+5,103,388</td><td>+15,465,047</td></tr>
<tr><td>总利润 %</td><td>+51,034%</td><td>+154,650%</td></tr>
</table>
<div class="highlight highlight-amber">
<strong>做空贡献了 75% 的总利润。</strong>这在直觉上可能令人意外ETH 在 2021-2026 整体上涨 174%),但仔细分析就合理了:<br>
① 上涨趋势中间的回调做空 + 2022 年熊市做空 = 大量做空利润<br>
② 合约的双向交易能力让策略在下跌中也能大幅盈利<br>
③ 做空利润 15.4M vs 做多 5.1M,说明策略在下跌行情中尤其高效
</div>
<h3 id="ch9-4">9.4 盈亏分布特征</h3>
<table>
<tr><th>指标</th><th>数值</th></tr>
<tr><td>最佳单笔交易</td><td>+36.09%</td></tr>
<tr><td>最差单笔交易</td><td>-5.41%</td></tr>
<tr><td>最佳交易日</td><td>+$4,499,935.76</td></tr>
<tr><td>最差交易日</td><td>-$530,721.16</td></tr>
<tr><td>最大连续盈利</td><td>6 笔</td></tr>
<tr><td>最大连续亏损</td><td>24 笔</td></tr>
<tr><td>盈利日 / 持平日 / 亏损日</td><td>370 / 841 / 635</td></tr>
<tr><td>盈利交易平均持仓</td><td>2 天 3 小时 9 分</td></tr>
<tr><td>亏损交易平均持仓</td><td>9 小时 22 分</td></tr>
<tr><td>最长盈利持仓</td><td>9 天 15 小时</td></tr>
<tr><td>最长亏损持仓</td><td>2 天 14 小时</td></tr>
</table>
<h3 id="ch9-5">9.5 v2.2c vs v2.2d 对比</h3>
<p>以下是两个版本在完全相同的回测条件下2021-01-01 → 2026-06-01, max_open_trades=1, wallet=10000的表现对比</p>
<table>
<tr><th>指标</th><th>v2.2c</th><th>v2.2d</th><th>变化</th></tr>
<tr><td>交易笔数</td><td>1,056</td><td>1,375</td><td>+30.2%</td></tr>
<tr><td>最终资金</td><td>$11,983,254</td><td>$20,578,435</td><td>+71.7%</td></tr>
<tr><td>总回报</td><td>+119,732%</td><td>+205,684%</td><td>+85,952pp</td></tr>
<tr><td>CAGR</td><td>270.15%</td><td>309.01%</td><td>+38.86pp</td></tr>
<tr><td>Sharpe</td><td>0.82</td><td>1.03</td><td>+0.21</td></tr>
<tr><td>利润因子</td><td>1.97</td><td>1.92</td><td>-0.05</td></tr>
<tr><td>最大回撤</td><td>17.96%</td><td>20.58%</td><td>+2.62pp</td></tr>
<tr><td>胜率</td><td>29.7%</td><td>28.9%</td><td>-0.8pp</td></tr>
<tr><td>做多/做空</td><td>585 / 471</td><td>748 / 627</td><td>+163 / +156</td></tr>
</table>
<div class="highlight highlight-green">
<strong>结论:</strong>v2.2d 在所有关键指标上全面优于 v2.2c。唯一增加的代价是回撤从 17.96% 升至 20.58%+2.62pp这是交易频率增加后的自然结果。Sharpe 比率突破 1.0 是策略成熟度的重要里程碑。
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 10 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch10">
<h2><span class="ch-num">第十章</span>策略演进史</h2>
<h3 id="ch10-1">10.1 v1.x 时代:试错与奠基</h3>
<table>
<tr><th>版本</th><th>核心改动</th><th>结果</th><th>教训</th></tr>
<tr><td>v0.x</td><td>EMA/ATR 等传统指标</td><td>已弃用</td><td>用户要求纯价格行为学</td></tr>
<tr><td>v1.0</td><td>5M TF, Spot</td><td>噪音太多,持仓 12min</td><td>时间框架太短</td></tr>
<tr><td>v1.1</td><td>1H TF, Futures</td><td>+61.52%</td><td>硬止损亏损太大</td></tr>
<tr><td>v1.2</td><td>Entry Candle 止损</td><td>Bug → 50笔全亏</td><td>return None 回退 25% 止损</td></tr>
<tr><td>v1.3</td><td>ATR 三阶段止损</td><td>-63.72%</td><td>ATR 不适合价格行为策略</td></tr>
<tr><td>v1.4</td><td>纯价格结构止损</td><td>+140.71%, PF=3.78</td><td>方向正确 ✅</td></tr>
<tr><td>v1.5</td><td>参数调优</td><td>+140.83%</td><td>持平,参数不敏感</td></tr>
<tr><td>v1.6</td><td>冷却期 + 活 S/R</td><td>旧最优基线</td><td>入场质量 > 止损优化</td></tr>
<tr><td>v1.7~v1.9</td><td>止损优化尝试</td><td>全部失败</td><td>任何过滤止损的方法都会误杀盈利</td></tr>
</table>
<h3 id="ch10-2">10.2 v2.x 时代:突破与优化</h3>
<table>
<tr><th>版本</th><th>核心改动</th><th>结果</th><th>意义</th></tr>
<tr><td>v2.0</td><td>B1 入场延迟确认</td><td>方向正确但降频严重</td><td>Trailing 胜率最高 91.7%</td></tr>
<tr><td>v2.1</td><td>D1 趋势强度过滤</td><td>ETH 4366% vs v1.6 3659%</td><td>首次全面超越 v1.6 ✅</td></tr>
<tr><td>v2.2b</td><td>参数精调</td><td>回测 4673%</td><td>部署至服务器 dry-run</td></tr>
<tr><td>v2.2c</td><td>1H S/R 替代 4H S/R</td><td>全周期 119,733%</td><td>1H S/R 方向正确,但有冷却期 bug</td></tr>
<tr><td style="background:#fef3c7;font-weight:700">v2.2d</td><td style="background:#fef3c7">冷却期修复</td><td style="background:#fef3c7;font-weight:700">全周期 205,684%</td><td style="background:#fef3c7">🔥 当前最优基线</td></tr>
</table>
<h3 id="ch10-3">10.3 关键教训总结</h3>
<ol>
<li><strong>纯价格行为学 > 指标策略:</strong>v0.x 的全部弃用已经证明了这一点。价格结构是最简单、最可解释、最普适的信号源。</li>
<li><strong>入场质量 > 止损优化:</strong>v1.7~v1.9 连续三次止损优化全部失败。策略的核心竞争力不来自"亏得少",而来自"赚得多"。</li>
<li><strong>简单二元过滤器容易误杀:</strong>H4 趋势过滤器减 8 笔止损但误杀 23 笔盈利单。教训:不要在入场端叠加过多过滤器。</li>
<li><strong>冷却期必须基于实际入场:</strong>v2.2c 的 bug 是教科书级的反面案例——用条件满足来模拟入场事件,在市场持续满足条件时导致策略"假死"。</li>
<li><strong>回测是唯一真理:</strong>每个假设都必须在回测中验证。直觉再好,数据不支持的改动就是错的。</li>
</ol>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 11 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch11">
<h2><span class="ch-num">第十一章</span>已知隐患与风险评估</h2>
<h3 id="ch11-1">11.1 策略层面风险</h3>
<table>
<tr><th style="width:5%">#</th><th>风险</th><th>严重度</th><th>详情</th></tr>
<tr>
<td>1</td>
<td><strong>低胜率心理压力</strong></td>
<td style="color:#dc2626;font-weight:700">🔴 高</td>
<td>28.9% 胜率意味着每 3-4 笔就有 2-3 笔止损。最大连续亏损 24 笔。实盘中连续亏损时人性会本能地想要干预——这恰恰会破坏策略的数学优势。</td>
</tr>
<tr>
<td>2</td>
<td><strong>过拟合风险</strong></td>
<td style="color:#f59e0b;font-weight:700">🟡 中</td>
<td>策略在 2021-2026 同一样本上迭代了 20+ 个版本。虽然有完整的牛熊覆盖和清晰的逻辑链,但无法排除一定程度的样本内过拟合。</td>
</tr>
<tr>
<td>3</td>
<td><strong>S/R 位移滞后</strong></td>
<td style="color:#f59e0b;font-weight:700">🟡 中</td>
<td>动态止损跟随最新 Swing Point 移动但在快速趋势中Swing Point 的形成有滞后。可能在 S/R 已经"过期"时仍在使用旧止损位。</td>
</tr>
<tr>
<td>4</td>
<td><strong>震荡市低效</strong></td>
<td style="color:#f59e0b;font-weight:700">🟡 中</td>
<td>策略是趋势跟踪策略在长时间窄幅震荡中交易机会减少且假突破增多。v3.x 波段策略正在开发中以覆盖这一场景。</td>
</tr>
<tr>
<td>5</td>
<td><strong>活 S/R 窗口敏感</strong></td>
<td style="color:#22c55e;font-weight:700">🟢 低</td>
<td>3 根 1H K 线的活 S/R 窗口对市场节奏敏感。快节奏市场中S/R 可能在窗口过期前就被突破;慢节奏中,窗口可能太短。但 2026-06-11 14:00 的实盘验证表明当前设置是合理的。</td>
</tr>
</table>
<h3 id="ch11-2">11.2 执行层面风险</h3>
<table>
<tr><th style="width:5%">#</th><th>风险</th><th>严重度</th><th>详情</th></tr>
<tr>
<td>1</td>
<td><strong>滑点导致回测低估</strong></td>
<td style="color:#f59e0b;font-weight:700">🟡 中</td>
<td>回测假设 0.05% 手续费,但未考虑市价单滑点。在 1H 级别中低频策略中滑点影响相对可控,但大资金阶段(>100万的流动性约束可能显著放大滑点。</td>
</tr>
<tr>
<td>2</td>
<td><strong>服务器故障</strong></td>
<td style="color:#f59e0b;font-weight:700">🟡 中</td>
<td>东京服务器2 vCPU, 2GB RAM, 40GB SSD运行 freqtrade + Dashboard + Halo + Shadowsocks 等多个服务资源有限。CPU/内存峰值可能导致策略执行延迟。</td>
</tr>
<tr>
<td>3</td>
<td><strong>API 限流</strong></td>
<td style="color:#22c55e;font-weight:700">🟢 低</td>
<td>Binance API 的 weight 限制1200/min。策略日均 0.7 笔交易API 调用极低频,几乎不可能触及限流。</td>
</tr>
</table>
<h3 id="ch11-3">11.3 外部不可控风险</h3>
<ul>
<li><strong>交易所风险:</strong>Binance 被监管关闭或限制提币(低概率,高影响)</li>
<li><strong>极端黑天鹅:</strong>类似 2020-03-12ETH 单日 -50%)的极端行情,策略的 15% 硬止损可能来不及执行</li>
<li><strong>市场结构剧变:</strong>ETH 从 PoW 转 PoS 后市场微观结构可能变化,价格行为学模式的有效性需要持续监控</li>
</ul>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- CHAPTER 12 -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="ch12">
<h2><span class="ch-num">第十二章</span>下一步优化方向</h2>
<h3 id="ch12-1">12.1 短期优化1-3个月</h3>
<table>
<tr><th style="width:5%">#</th><th>方向</th><th>优先级</th><th>说明</th></tr>
<tr>
<td>1</td>
<td><strong>Out-of-Sample 验证</strong></td>
<td style="color:#dc2626;font-weight:700">P0</td>
<td>使用 2025-2026 年 dry-run 数据(未在优化中使用)验证策略的样本外表现。如果显著差于回测 → 过拟合证据。</td>
</tr>
<tr>
<td>2</td>
<td><strong>实盘滑点数据收集</strong></td>
<td style="color:#f59e0b;font-weight:700">P1</td>
<td>记录 dry-run 中每笔订单的实际成交价与信号价的偏差,量化真实滑点成本,修正回测收益预估。</td>
</tr>
<tr>
<td>3</td>
<td><strong>每日监控自动化</strong></td>
<td style="color:#f59e0b;font-weight:700">P1</td>
<td>完善 daily_brief.py增加异常检测连续亏损超阈值、长期无信号、S/R 异常跳动等),微信主动推送。</td>
</tr>
<tr>
<td>4</td>
<td><strong>多品种验证BTC</strong></td>
<td style="color:#22c55e;font-weight:700">P2</td>
<td>在 BTC/USDT 上回测 v2.2d,评估策略的跨品种通用性。如果 BTC 表现差 → 可能是 ETH 特有的过拟合。</td>
</tr>
</table>
<h3 id="ch12-2">12.2 中期优化3-12个月</h3>
<table>
<tr><th style="width:5%">#</th><th>方向</th><th>说明</th></tr>
<tr>
<td>1</td>
<td><strong>市场环境自适应</strong></td>
<td>根据当前市场波动率/趋势强度自动调整参数(如 cooling_bars、trend_strength_min而非使用固定值。牛市放宽冷却期熊市收紧。</td>
</tr>
<tr>
<td>2</td>
<td><strong>止损结构确认</strong></td>
<td>在 custom_stoploss 中增加"结构破坏检测"——不只在 S/R 位止损,还检测 S/R 是否已被有效突破(收盘价穿透 + 下一根确认),提高止损的精准度。</td>
</tr>
<tr>
<td>3</td>
<td><strong>波段策略完善v3.x</strong></td>
<td>完成《区间》阅读后,继续优化 v3.1 波段策略,覆盖趋势策略在震荡市中的交易空白,实现策略组合互补。</td>
</tr>
<tr>
<td>4</td>
<td><strong>多因子评分替代二元过滤</strong></td>
<td>将当前的 6 项布尔 AND 条件改为加权评分机制。某些条件在特定市场环境下权重更高,而非一刀切的"全部满足才入场"。</td>
</tr>
</table>
<h3 id="ch12-3">12.3 长期愿景</h3>
<ul>
<li><strong>多品种多策略组合:</strong>趋势v2.2d+ 波段v3.x+ 剥头皮待突破ETH + BTC + 其他主流币,不同策略覆盖不同市场环境</li>
<li><strong>家庭电脑远程回测:</strong>通过 frp/Tailscale 将家里高性能电脑作为回测/机器学习工作站,东京服务器仅负责实时交易执行</li>
<li><strong>策略"黑箱"监控面板:</strong>完整的策略健康度仪表盘——回撤预警、胜率漂移检测、信号质量评分、参数稳定性监控</li>
<li><strong>实盘小资金验证:</strong>dry-run 稳定 3-6 个月后,用小资金(如 $1,000实盘验证 3 个月,确认回测到实盘的折损率</li>
</ul>
<div class="highlight highlight-amber">
<strong>⚠️ 优化铁律:</strong>v3.2 的教训历历在目——多一层过滤就多一层误伤。所有优化必须经过严格的 A/B 回测对比,绝不做"我觉得这个方向应该有用"的改动。控制变量,一次只改一项,回测结果说话。
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════ -->
<!-- APPENDICES -->
<!-- ═══════════════════════════════════════════════════════════════ -->
<div class="chapter" id="appendix">
<h2><span class="ch-num">附录</span></h2>
<h3 id="appendix-a">附录A完整参数表</h3>
<table>
<tr><th>参数</th><th>类型</th><th>默认值</th><th>范围</th><th>空间</th></tr>
<tr><td>swing_lookback_d1</td><td>IntParameter</td><td>10</td><td>8 ~ 14</td><td>buy</td></tr>
<tr><td>swing_lookback_h4</td><td>IntParameter</td><td>8</td><td>5 ~ 10</td><td>buy</td></tr>
<tr><td>swing_lookback_1h</td><td>IntParameter</td><td>5</td><td>3 ~ 7</td><td>buy</td></tr>
<tr><td>pin_bar_wick_ratio</td><td>IntParameter</td><td>60</td><td>50 ~ 70</td><td>buy</td></tr>
<tr><td>max_stop_dist</td><td>IntParameter</td><td>50</td><td>20 ~ 50</td><td>buy</td></tr>
<tr><td>cooldown_bars</td><td>IntParameter</td><td>6</td><td>3 ~ 12</td><td>buy</td></tr>
<tr><td>trend_strength_min</td><td>IntParameter</td><td>-20</td><td>-50 ~ 20</td><td>buy</td></tr>
</table>
<h3 id="appendix-b">附录B回测环境配置</h3>
<pre><code>{
"max_open_trades": 1,
"dry_run_wallet": 10000,
"stake_amount": "unlimited",
"trading_mode": "futures",
"margin_mode": "cross",
"exchange": "binance",
"pair_whitelist": ["ETH/USDT:USDT"],
"timeframe": "1h",
"timerange": "20210101-20260601",
"fee": 0.0005
}</code></pre>
<h3 id="appendix-c">附录C策略完整源码</h3>
<p>策略源码文件452 行 Python位于</p>
<ul>
<li><strong>本地副本:</strong><code>structure_flow_strategy_v2_2d_local.py</code></li>
<li><strong>服务器部署:</strong><code>~/freqtrade/user_data/strategies/structure_flow_strategy_v2_2d.py</code></li>
</ul>
<p>源码结构:</p>
<ul>
<li><code>_detect_swing_points()</code> — Swing Point 检测(行 42-57</li>
<li><code>_build_structure()</code> — 结构分析:趋势 + S/R + 供需区域(行 63-126</li>
<li><code>_detect_candle_patterns()</code> — K线形态识别行 132-155</li>
<li><code>_apply_cooldown()</code> — 冷却期(行 161-184</li>
<li><code>populate_indicators_1d()</code> — D1 指标(行 190-204</li>
<li><code>populate_indicators_4h()</code> — 4H 指标(行 210-252</li>
<li><code>populate_indicators()</code> — 1H 主指标(行 258-324</li>
<li><code>populate_entry_trend()</code> — 入场信号(行 330-378</li>
<li><code>populate_exit_trend()</code> — 出场信号(行 384-391</li>
<li><code>custom_stoploss()</code> — 动态止损(行 397-426</li>
<li><code>plot_config()</code> — 可视化配置(行 432-451</li>
</ul>
<h3 id="appendix-d">附录D术语表</h3>
<table>
<tr><th style="width:22%">术语</th><th>英文</th><th>解释</th></tr>
<tr><td>Swing Point</td><td>Swing Point</td><td>摆动点局部价格极值。Swing High = 比左右各 N 根 K 线都高的高点Swing Low 同理。</td></tr>
<tr><td>S/R</td><td>Support / Resistance</td><td>支撑/阻力:最近一个 Swing Low 为支撑,最近一个 Swing High 为阻力。</td></tr>
<tr><td>Demand Zone</td><td>Demand Zone</td><td>需求区:价格在 S/R 区间的下 35% 区域,买方力量聚集。</td></tr>
<tr><td>Supply Zone</td><td>Supply Zone</td><td>供给区:价格在 S/R 区间的上 35%(即 65%~100%),卖方力量聚集。</td></tr>
<tr><td>活 S/R</td><td>Alive S/R</td><td>在最近 3 根 K 线内被测试过并且守住的支撑/阻力。3 根窗口基于 rolling(3).max()。</td></tr>
<tr><td>Pin Bar</td><td>Pin Bar</td><td>影线极长、实体极短的单 K 线形态。影线占比 > 60% 阈值。</td></tr>
<tr><td>吞没形态</td><td>Engulfing</td><td>当前 K 线完全吞没前一根 K 线的两 K 线组合反转信号。</td></tr>
<tr><td>冷却期</td><td>Cooldown</td><td>入场后禁止再次入场的 K 线数量。v2.2d 基于实际入场事件实现。</td></tr>
<tr><td>趋势强度</td><td>Trend Strength</td><td>4H 级别最近两个 Swing Point 的间距变化率之和,衡量趋势的"力道"。</td></tr>
<tr><td>追踪止损</td><td>Trailing Stop Loss</td><td>随 1H S/R 位动态移动的止损。支撑上移 → 做多止损上移,实现利润保护。</td></tr>
<tr><td>CAGR</td><td>Compound Annual Growth Rate</td><td>年化复合增长率。v2.2d 为 309.01%。</td></tr>
<tr><td>Sharpe 比率</td><td>Sharpe Ratio</td><td>风险调整后收益。>1.0 为良好v2.2d 为 1.03。</td></tr>
<tr><td>SQN</td><td>System Quality Number</td><td>系统质量指数。>2.0 为良好v2.2d 为 2.88。</td></tr>
<tr><td>Expectancy</td><td>Expectancy</td><td>每笔交易的期望利润。v2.2d 为 $14,959Ratio 0.65)。</td></tr>
</table>
<div style="height:40px"></div>
<div style="text-align:center; padding:40px 0; border-top:1px solid #e5e7eb; margin-top:40px">
<p style="color:#888; font-size:10pt">— Structure Flow Strategy v2.2d 完整说明书 · 终 —</p>
<p style="color:#aaa; font-size:9pt; margin-top:4px">2026年6月11日 · FXY · 东京服务器 dry-run 运行中</p>
</div>
</div>
</body>
</html>