v1.5: 最小化过滤器 + 纯结构突破信号
This commit is contained in:
49
strategy.py
49
strategy.py
@ -1,17 +1,16 @@
|
||||
"""
|
||||
Structure Flow Strategy v1.4
|
||||
Structure Flow Strategy v1.5
|
||||
=======================
|
||||
变更记录:
|
||||
v1.0 (2026-06-07): 纯价格结构策略,D1定方向→4H定位→1H入场
|
||||
v1.1 (2026-06-07): 1H futures,结构止损,首次回测成功(+61.52%)
|
||||
v1.2 (2026-06-07): Entry Candle止损,bug导致50笔硬止损全亏
|
||||
v1.3 (2026-06-07): ATR动态止损,结果-63.72%,胜率20.2%
|
||||
v1.4 (2026-06-07): ===== 回归纯价格结构止损 =====
|
||||
- 完全移除ATR(违背价格行为内核)
|
||||
- 止损 = support_4h(resistance_4h) ± 缓冲
|
||||
- support_4h随新Swing Low自动更新 → 天然追踪止损
|
||||
- 新增入场过滤:止损距离>3%则跳过(赔率太差)
|
||||
核心哲学:止损必须在价格结构位,不在指标计算结果
|
||||
v1.4 (2026-06-07): 回归纯价格结构止损,+140.71%,胜率38.7%
|
||||
v1.5 (2026-06-07): ===== 参数调优 =====
|
||||
- stoploss -5% → -15%,释放结构止损空间
|
||||
- max_stop_dist 3% → 5%,增加交易频率
|
||||
其他逻辑与v1.4完全相同
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
@ -22,19 +21,17 @@ from freqtrade.strategy import IStrategy, IntParameter, informative
|
||||
from freqtrade.persistence import Trade
|
||||
|
||||
|
||||
class StructureFlowStrategyV14(IStrategy):
|
||||
class StructureFlowStrategyV15(IStrategy):
|
||||
"""
|
||||
Structure Flow Strategy v1.4 — 纯价格结构,零指标
|
||||
Structure Flow Strategy v1.5 — 纯价格结构,零指标
|
||||
|
||||
止损逻辑(v1.4重写,完全移除ATR):
|
||||
- 做多止损 = support_4h - 0.1%缓冲
|
||||
- 做空止损 = resistance_4h + 0.1%缓冲
|
||||
- support_4h / resistance_4h 随时间更新 → 天然追踪止损
|
||||
- 硬止损安全网:-5%(stoploss属性)
|
||||
v1.5改动(相对于v1.4):
|
||||
- stoploss -5% → -15%(硬止损放宽,让结构止损真正生效)
|
||||
- max_stop_dist 3% → 5%(增加交易频率)
|
||||
"""
|
||||
|
||||
can_short = True
|
||||
stoploss = -0.05
|
||||
stoploss = -0.15 # v1.5: -5% → -15%
|
||||
use_custom_stoploss = True
|
||||
minimal_roi = {"0": 100}
|
||||
max_open_trades = 1
|
||||
@ -47,8 +44,8 @@ class StructureFlowStrategyV14(IStrategy):
|
||||
swing_lookback_d1 = IntParameter(8, 14, default=10, space="buy")
|
||||
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=30, space="buy")
|
||||
# v1.5: 默认值从30→50(3%→5%)
|
||||
max_stop_dist = IntParameter(20, 50, default=50, space="buy")
|
||||
|
||||
# =====================
|
||||
# 工具:Swing Point 检测
|
||||
@ -263,7 +260,7 @@ class StructureFlowStrategyV14(IStrategy):
|
||||
1. D1 上升结构(trend_up_1d)— 宏观方向
|
||||
2. 4H 需求区域(in_demand_4h)— 在支撑附近
|
||||
3. 1H 看涨 K 线形态(bullish_signal)
|
||||
4. 止损距离 ≤ max_stop_dist% — 赔率过滤
|
||||
4. 止损距离 ≤ max_stop_dist% — 赔率过滤(v1.5: 默认5%)
|
||||
|
||||
做空条件:
|
||||
1. D1 下降结构(trend_down_1d)
|
||||
@ -285,8 +282,6 @@ class StructureFlowStrategyV14(IStrategy):
|
||||
dataframe[col] = dataframe[col].fillna(False)
|
||||
|
||||
# ── 做多 ──
|
||||
# 止损距离 = (入场价 - support_4h) / 入场价
|
||||
# support_4h 已 ffilled,取当前值
|
||||
long_stop_dist = (dataframe["open"] - dataframe["support_4h"]) / dataframe["open"]
|
||||
|
||||
long_conditions = (
|
||||
@ -327,7 +322,7 @@ class StructureFlowStrategyV14(IStrategy):
|
||||
return dataframe
|
||||
|
||||
# =====================
|
||||
# 动态止损 — v1.4 重写:纯价格结构
|
||||
# 动态止损 — 纯价格结构(基于Swing Point)
|
||||
# =====================
|
||||
|
||||
def custom_stoploss(
|
||||
@ -341,7 +336,7 @@ class StructureFlowStrategyV14(IStrategy):
|
||||
**kwargs,
|
||||
) -> float:
|
||||
"""
|
||||
v1.4 止损逻辑:完全基于价格结构,零指标。
|
||||
止损逻辑:完全基于价格结构,零指标。
|
||||
|
||||
止损位:
|
||||
做多 → support_4h - 0.1%缓冲(最近4H Swing Low下方)
|
||||
@ -350,12 +345,10 @@ class StructureFlowStrategyV14(IStrategy):
|
||||
support_4h / resistance_4h 随新Swing Point自动更新,
|
||||
天然形成追踪止损效果。
|
||||
|
||||
永不返回 None,始终返回显式止损比率。
|
||||
最终截断在 -5% / +5% 安全网内。
|
||||
v1.5: 硬止损从-5%放宽到-15%,让结构止损真正生效。
|
||||
"""
|
||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
if dataframe is None or len(dataframe) == 0:
|
||||
# 极端情况:返回2%固定止损
|
||||
return -0.02 if not trade.is_short else 0.02
|
||||
|
||||
last = dataframe.iloc[-1]
|
||||
@ -367,7 +360,8 @@ class StructureFlowStrategyV14(IStrategy):
|
||||
# 止损 = support_4h 下方 0.1%
|
||||
sl_price = support * 0.999
|
||||
sl_ratio = (sl_price / current_rate) - 1.0
|
||||
return max(sl_ratio, -0.05)
|
||||
# v1.5: 硬止损从-5% → -15%
|
||||
return max(sl_ratio, -0.15)
|
||||
else:
|
||||
resistance = last.get("resistance_4h", np.nan)
|
||||
if pd.isna(resistance) or resistance <= 0:
|
||||
@ -375,7 +369,8 @@ class StructureFlowStrategyV14(IStrategy):
|
||||
# 止损 = resistance_4h 上方 0.1%
|
||||
sl_price = resistance * 1.001
|
||||
sl_ratio = 1.0 - (sl_price / current_rate)
|
||||
return min(sl_ratio, 0.05)
|
||||
# v1.5: 硬止损从+5% → +15%
|
||||
return min(sl_ratio, 0.15)
|
||||
|
||||
# =====================
|
||||
# Plot config
|
||||
|
||||
Reference in New Issue
Block a user