From 24d01cba0d9b4907ad2360f934611cd25fe833ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Mon, 23 Feb 2026 17:44:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(trade=5Frecommender):=20=E5=BC=95=E5=85=A5?= =?UTF-8?q?4H=E8=B6=8B=E5=8A=BF=E8=BF=87=E6=BB=A4=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BB=A5=E4=BC=98=E5=8C=96=E4=BA=A4=E6=98=93=E6=8E=A8=E8=8D=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在交易推荐系统中新增 `BLOCK_LONG_WHEN_4H_DOWN` 和 `BLOCK_SHORT_WHEN_4H_UP` 配置,允许在4H趋势下跌时禁止开多和在4H趋势上涨时禁止开空。此改动增强了策略的灵活性与风险控制,确保推荐逻辑与市场趋势一致,提升交易决策的准确性。 --- trading_system/trade_recommender.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/trading_system/trade_recommender.py b/trading_system/trade_recommender.py index 29604fc..f83a6dd 100644 --- a/trading_system/trade_recommender.py +++ b/trading_system/trade_recommender.py @@ -347,10 +347,21 @@ class TradeRecommender: reasons.append("4H周期共振确认") # 推荐系统:默认不再输出“逆4H趋势”的推荐(用户反馈方向不对的主要来源) - # 如果未来需要放开,可做成配置项 ALLOW_COUNTER_TREND_RECOMMENDATIONS。 + # 与交易策略一致:使用 BLOCK_LONG_WHEN_4H_DOWN / BLOCK_SHORT_WHEN_4H_UP 控制 + block_long_4h_down = bool(config.TRADING_CONFIG.get("BLOCK_LONG_WHEN_4H_DOWN", False)) + block_short_4h_up = bool(config.TRADING_CONFIG.get("BLOCK_SHORT_WHEN_4H_UP", True)) if direction and trend_4h and trend_4h in ("up", "down"): - if (direction == 'BUY' and trend_4h == 'down') or (direction == 'SELL' and trend_4h == 'up'): - reasons.append("❌ 逆4H趋势,跳过推荐") + if block_long_4h_down and direction == 'BUY' and trend_4h == 'down': + reasons.append("❌ 4H趋势下跌,禁止开多(BLOCK_LONG_WHEN_4H_DOWN=true),跳过推荐") + return { + 'should_trade': False, + 'direction': direction, + 'reason': ', '.join(reasons) if reasons else '逆趋势', + 'strength': max(0, signal_strength - 2), + 'trend_4h': trend_4h + } + if block_short_4h_up and direction == 'SELL' and trend_4h == 'up': + reasons.append("❌ 4H趋势上涨,禁止开空(BLOCK_SHORT_WHEN_4H_UP=true),跳过推荐") return { 'should_trade': False, 'direction': direction,