From 040473d4d3d9e251b09f80c2bf6c12124b316a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Tue, 3 Feb 2026 11:26:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=8F=E6=8D=9F=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trading_system/market_scanner.py | 22 ++++++++++++++++------ trading_system/strategy.py | 28 ++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/trading_system/market_scanner.py b/trading_system/market_scanner.py index ce10057..05957ce 100644 --- a/trading_system/market_scanner.py +++ b/trading_system/market_scanner.py @@ -425,14 +425,24 @@ class MarketScanner: if ema20 and ema50: if current_price > ema20 > ema50: # 上升趋势 if trend_4h in ('up', 'neutral', None): - signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross'] - if direction is None: - direction = 'BUY' + # 冲突检查 + if direction == 'SELL': + signal_strength = 0 + direction = None + else: + signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross'] + if direction is None: + direction = 'BUY' elif current_price < ema20 < ema50: # 下降趋势 if trend_4h in ('down', 'neutral', None): - signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross'] - if direction is None: - direction = 'SELL' + # 冲突检查 + if direction == 'BUY': + signal_strength = 0 + direction = None + else: + signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross'] + if direction is None: + direction = 'SELL' # 价格与EMA20关系 if ema20: diff --git a/trading_system/strategy.py b/trading_system/strategy.py index 69b9c40..eb294c4 100644 --- a/trading_system/strategy.py +++ b/trading_system/strategy.py @@ -440,10 +440,16 @@ class TradingStrategy: if trend_4h in ('up', 'neutral'): # OPTIMIZATION: 添加 RSI 过滤 if rsi is None or rsi < 70: - signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross'] - reasons.append("EMA20上穿EMA50,上升趋势") - if direction is None: - direction = 'BUY' + # 冲突检查:如果已有方向且与当前不符,则是严重冲突 + if direction == 'SELL': + reasons.append("❌ 信号冲突:MACD看空但EMA看多") + signal_strength = 0 + direction = None + else: + signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross'] + reasons.append("EMA20上穿EMA50,上升趋势") + if direction is None: + direction = 'BUY' else: reasons.append(f"1H均线向上但4H趋势相反({trend_4h}),禁止逆势") elif current_price < ema20 < ema50: # 下降趋势 @@ -451,10 +457,16 @@ class TradingStrategy: if trend_4h in ('down', 'neutral'): # OPTIMIZATION: 添加 RSI 过滤 if rsi is None or rsi > 30: - signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross'] - reasons.append("EMA20下穿EMA50,下降趋势") - if direction is None: - direction = 'SELL' + # 冲突检查:如果已有方向且与当前不符,则是严重冲突 + if direction == 'BUY': + reasons.append("❌ 信号冲突:MACD看多但EMA看空") + signal_strength = 0 + direction = None + else: + signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross'] + reasons.append("EMA20下穿EMA50,下降趋势") + if direction is None: + direction = 'SELL' else: reasons.append(f"1H均线向下但4H趋势相反({trend_4h}),禁止逆势")