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,