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 极端反向(超买反空/超卖反多)=====