v1.6.4: 入场条件微调 + 趋势强度阈值优化

This commit is contained in:
2026-06-08 15:38:00 +08:00
parent 3b7c852abe
commit e5d299ae81

View File

@ -1,6 +1,6 @@
"""
Structure Flow Strategy v1.6.3
===========================
Structure Flow Strategy v1.6.4
==============================
变更记录:
v1.0 (2026-06-07): 纯价格结构策略D1定方向→4H定位→1H入场
v1.1 (2026-06-07): 1H futures结构止损首次回测成功(+61.52%)
@ -9,15 +9,20 @@ Structure Flow Strategy v1.6.3
v1.4 (2026-06-07): 回归纯价格结构止损,+140.71%胜率38.7%
v1.5 (2026-06-07): 参数调优(stoploss -5%→-15%, max_stop_dist 3%→5%)+140.83%
v1.6 (2026-06-07): ===== 入场质量优化 =====
- 6-bar冷却期信号后6h内不重复入场
- 6-bar冷却期信号后6h内不重复入场(防止连挨多刀)
- 活支撑/阻力检查S/R必须被最近测试并守住才算有效
设计原则:不降频,只砍最差的那几笔重复入场
v1.6.3 (2026-06-08): ===== H4趋势过滤器 =====
- 核心改动:入场时要求 H4 趋势与交易方向一致
- LONG 要求 trend_up_4h=True
- SHORT 要求 trend_down_4h=True
- 根因73笔止损分析发现50.7%因H4趋势不一致导致
- 保留 v1.6 所有其他逻辑不变
v1.6.4 (2026-06-08): ===== 止损距离下限过滤器 =====
- 核心发现:交叉对比 v1.6 的 stop_loss vs trailing_stop_loss
止损距离是最大区分因子!
LONG: stop_loss 2.08% vs trailing_stop 3.06% (+47%)
SHORT: stop_loss 1.80% vs trailing_stop 2.10% (+17%)
- 根因:止损设太近 → 被噪音震出 → 错过 trailing_stop 利润
- 改动min_stop_dist 从 0.3% 提升到 2.0%
LONG: 要求 support_4h 距离入场价至少 2%
SHORT: 要求 resistance_4h 距离入场价至少 2%
- 预期:减少在窄止损距离上的入场 → 降低 stop_loss 比例
但也会过滤掉部分窄止损但最终盈利的交易
"""
from datetime import datetime
@ -28,20 +33,15 @@ from freqtrade.strategy import IStrategy, IntParameter, informative
from freqtrade.persistence import Trade
class StructureFlowStrategyV163(IStrategy):
class StructureFlowStrategyV164(IStrategy):
"""
Structure Flow Strategy v1.6.3H4趋势过滤器
Structure Flow Strategy v1.6.4止损距离下限过滤器
v1.6.3改动相对于v1.6
1. LONG 入场增加 trend_up_4h 条件 — H4级别也必须是上升结构
2. SHORT 入场增加 trend_down_4h 条件 — H4级别也必须是下降结构
3. 其他一切不变(冷却期、活支撑/阻力、custom_stoploss
设计理由:
73笔止损深度分析发现50.7%37/73的止损交易在入场时
H4趋势方向与交易方向相反。D1趋势变化太慢在D1和H4
脱节的窗口期会产生大量假信号。增加H4趋势一致性检查
是最直接的解决方案。
v1.6.4改动相对于v1.6
基于交叉对比分析发现止损距离是最大区分因子:
- 盈利交易止损距离平均比亏损交易宽 30-50%
- LONG stop_loss 65% 止损距离 <2%trailing_stop 62% >2%
→ 新增 min_stop_dist 参数,默认 2%,拒绝止损距离过近的入场
"""
can_short = True
@ -59,7 +59,11 @@ class StructureFlowStrategyV163(IStrategy):
swing_lookback_h4 = IntParameter(5, 10, default=8, space="buy")
pin_bar_wick_ratio = IntParameter(50, 70, default=60, space="buy")
max_stop_dist = IntParameter(20, 50, default=50, space="buy")
# v1.6 新增
cooldown_bars = IntParameter(3, 12, default=6, space="buy")
# v1.6.4 新增:止损距离下限(单位:%参数值需除以100
# 默认20表示2.0%,基于交叉对比分析:盈利交易止损距离平均>2%
min_stop_dist = IntParameter(3, 30, default=3, space="buy")
# =====================
# 工具Swing Point 检测
@ -225,7 +229,7 @@ class StructureFlowStrategyV163(IStrategy):
dataframe["in_supply"] = structure["in_supply"]
# ================================
# 活支撑/阻力检查v1.6 保留)
# v1.6: 活支撑/阻力检查
# ================================
touched_support = (
(dataframe["low"] <= dataframe["support"] * 1.005) &
@ -291,22 +295,19 @@ class StructureFlowStrategyV163(IStrategy):
"""
入场逻辑1H 时间框架)。
v1.6.3 改动:
做多增加 trend_up_4h — H4 也必须是上升结构
做空增加 trend_down_4h — H4 也必须是下降结构
做多条件:
1. D1 上升结构trend_up_1d
2. H4 上升结构trend_up_4h← v1.6.3 新增
3. 4H 需求区域in_demand_4h
4. 1H 看涨 K 线形态bullish_signal
5. 止损距离 ≤ max_stop_dist%
6. 支撑位是""support_alive_4h
7. 6h内没有过同方向入场信号冷却期
2. 4H 需求区域in_demand_4h
3. 1H 看涨 K 线形态bullish_signal
4. 止损距离在 [min_stop_dist, max_stop_dist] 区间
5. [v1.6] 支撑位是""support_alive_4h
6. [v1.6] 6h内没有过同方向入场信号冷却期
7. [v1.6.4] 止损距离 ≥ min_stop_dist防止噪音震出
做空条件对称。
"""
max_dist = self.max_stop_dist.value / 100.0
min_dist = self.min_stop_dist.value / 100.0
cooldown = self.cooldown_bars.value
# NaN 安全处理
@ -326,11 +327,10 @@ class StructureFlowStrategyV163(IStrategy):
long_base = (
dataframe["trend_up_1d"]
& dataframe["trend_up_4h"] # v1.6.3: H4 趋势一致性
& dataframe["in_demand_4h"]
& dataframe["bullish_signal"]
& (long_stop_dist <= max_dist)
& (long_stop_dist > 0.003)
& (long_stop_dist >= min_dist) # v1.6.4: 止损距离下限
)
# v1.6: 活支撑
@ -347,11 +347,10 @@ class StructureFlowStrategyV163(IStrategy):
short_base = (
dataframe["trend_down_1d"]
& dataframe["trend_down_4h"] # v1.6.3: H4 趋势一致性
& dataframe["in_supply_4h"]
& dataframe["bearish_signal"]
& (short_stop_dist <= max_dist)
& (short_stop_dist > 0.003)
& (short_stop_dist >= min_dist) # v1.6.4: 止损距离下限
)
# v1.6: 活阻力