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