From 0f0aa1bf5d4190e8d49c48489a6f8d02e9fcdb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Wed, 25 Feb 2026 13:28:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(market=5Fscanner,=20strategy):=20=E5=BC=95?= =?UTF-8?q?=E5=85=A5=E5=9B=9E=E9=80=80=E4=BF=A1=E5=8F=B7=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BB=A5=E4=BC=98=E5=8C=96=E4=BF=A1=E5=8F=B7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在市场扫描和交易策略中增加了回退信号逻辑,当信号强度为零且方向未明确时,采用RSI、MACD和布林带的综合信号进行判断,避免长期无推荐。这一改动旨在提升策略的灵活性与可用性,确保在市场波动时仍能提供有效的交易建议。 --- trading_system/market_scanner.py | 32 ++++++++++++++++++++++++++++++++ trading_system/strategy.py | 12 ++++++++++++ 2 files changed, 44 insertions(+) diff --git a/trading_system/market_scanner.py b/trading_system/market_scanner.py index 58dd1af..007f69e 100644 --- a/trading_system/market_scanner.py +++ b/trading_system/market_scanner.py @@ -854,6 +854,38 @@ class MarketScanner: # 强度上限归一到 0-10 signal_strength = max(0, min(int(signal_strength), 10)) + # 回退:趋势逻辑过严时(MACD/EMA/4H 未同时满足),用 RSI/MACD/布林 综合得分给弱信号,避免长期全 0 + if signal_strength == 0 and direction is None and signal_score >= 5: + fallback_strength = min(5, max(1, signal_score - 3)) # 5->2, 6->3, 7->4, 8+->5 + if rsi is not None: + if rsi < 35: + direction = 'BUY' + signal_strength = fallback_strength + elif rsi > 65: + direction = 'SELL' + signal_strength = fallback_strength + if direction is None and bollinger: + if current_price <= bollinger.get('lower', float('inf')): + direction = 'BUY' + signal_strength = fallback_strength + elif current_price >= bollinger.get('upper', -float('inf')): + direction = 'SELL' + signal_strength = fallback_strength + if direction is None and macd and macd.get('histogram') is not None: + if macd['histogram'] > 0 and macd.get('macd', 0) > macd.get('signal', 0): + direction = 'BUY' + signal_strength = fallback_strength + elif macd['histogram'] < 0 and macd.get('macd', 0) < macd.get('signal', 0): + direction = 'SELL' + signal_strength = fallback_strength + if direction is None and ema20 and ema50: + if current_price > ema20 > ema50: + direction = 'BUY' + signal_strength = fallback_strength + elif current_price < ema20 < ema50: + direction = 'SELL' + signal_strength = fallback_strength + # ===== 趋势状态缓存(用于后续“入场时机过滤”)===== try: # 只有在方向明确且信号强度达到最小门槛时,才记录趋势状态 diff --git a/trading_system/strategy.py b/trading_system/strategy.py index 73622bf..4fc4800 100644 --- a/trading_system/strategy.py +++ b/trading_system/strategy.py @@ -680,6 +680,18 @@ class TradingStrategy: signal_strength = max(0, min(int(signal_strength), 10)) except Exception: pass + # 回退:趋势逻辑过严导致 0 时,采用扫描器回退信号(RSI/MACD/布林综合),避免长期无推荐 + if signal_strength == 0 and direction is None: + scan_strength = symbol_info.get('signal_strength', 0) + scan_dir = symbol_info.get('direction') + try: + scan_strength = int(scan_strength) if scan_strength is not None else 0 + except (TypeError, ValueError): + scan_strength = 0 + if scan_strength >= 1 and scan_dir in ('BUY', 'SELL'): + signal_strength = min(scan_strength, 5) + direction = scan_dir + reasons.append("采用扫描器综合信号(弱)") should_trade = signal_strength >= min_signal_strength and direction is not None # ===== RSI / 24h 涨跌幅过滤:做多不追高、做空不杀跌;可选 RSI 极端反向(超买反空/超卖反多)=====