feat(trade_recommender): 引入4H趋势过滤逻辑以优化交易推荐
在交易推荐系统中新增 `BLOCK_LONG_WHEN_4H_DOWN` 和 `BLOCK_SHORT_WHEN_4H_UP` 配置,允许在4H趋势下跌时禁止开多和在4H趋势上涨时禁止开空。此改动增强了策略的灵活性与风险控制,确保推荐逻辑与市场趋势一致,提升交易决策的准确性。
This commit is contained in:
parent
d42cee2f1a
commit
24d01cba0d
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user