From d4edc16f439e475227de45b24aac85d780b5df20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Tue, 27 Jan 2026 08:44:35 +0800 Subject: [PATCH] a --- trading_system/market_scanner.py | 94 +++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 8 deletions(-) diff --git a/trading_system/market_scanner.py b/trading_system/market_scanner.py index 270d01d..52f0edb 100644 --- a/trading_system/market_scanner.py +++ b/trading_system/market_scanner.py @@ -149,13 +149,14 @@ class MarketScanner: if min_volume_strict > min_volume_normal: logger.info(f"使用严格成交量过滤: {min_volume_strict/1000000:.1f}M USDT (原标准: {min_volume_normal/1000000:.1f}M USDT)") - # 按信号得分和涨跌幅综合排序,取前N个 - # 优先考虑技术指标信号得分高的 + # ⚠️ 2026-01-27优化:按真实的signal_strength排序,而不是简单的signalScore + # 优先考虑信号强度高的交易对(8-10分),提升胜率 sorted_results = sorted( filtered_results, key=lambda x: ( - x.get('signalScore', 0) * 10, # 信号得分权重更高 - abs(x['changePercent']) # 其次考虑涨跌幅 + x.get('signal_strength', 0) * 100, # 信号强度权重最高(乘以100确保优先级) + x.get('signalScore', 0) * 10, # 其次考虑信号得分(兼容性) + abs(x['changePercent']) # 最后考虑涨跌幅 ), reverse=True ) @@ -198,12 +199,13 @@ class MarketScanner: for i, symbol_info in enumerate(top_n, 1): rsi_str = f"RSI:{symbol_info.get('rsi', 0):.1f}" if symbol_info.get('rsi') else "RSI:N/A" regime_str = symbol_info.get('marketRegime', 'unknown') - score_str = f"信号:{symbol_info.get('signalScore', 0)}" + # ⚠️ 2026-01-27优化:显示真实的signal_strength,而不是signalScore + strength_str = f"信号:{symbol_info.get('signal_strength', symbol_info.get('signalScore', 0))}" logger.info( f"{i}. {symbol_info['symbol']}: " f"{symbol_info['changePercent']:.2f}% | " - f"{rsi_str} | {regime_str} | {score_str} | " + f"{rsi_str} | {regime_str} | {strength_str} | " f"价格: {symbol_info['price']:.4f}" ) @@ -340,7 +342,7 @@ class MarketScanner: except Exception as e: logger.debug(f"{symbol} 缓存技术指标计算结果失败: {e}") - # 计算交易信号得分(用于排序) + # 计算交易信号得分(用于排序)- 保留用于兼容性 signal_score = 0 # RSI信号(均值回归) @@ -375,6 +377,80 @@ class MarketScanner: elif current_price < ema20 < ema50: # 下降趋势 signal_score += 1 + # ⚠️ 2026-01-27优化:计算真实的signal_strength(用于排序和筛选) + # 使用与strategy.py相同的逻辑,确保排序依据与交易判断一致 + signal_strength = 0 + direction = None + + # 获取4H周期当前价格(用于判断4H趋势) + price_4h = close_prices_4h[-1] if len(close_prices_4h) > 0 else current_price + + # 判断4H周期趋势方向 + trend_4h = None + if ema20_4h is not None: + if price_4h > ema20_4h: + trend_4h = 'up' + elif price_4h < ema20_4h: + trend_4h = 'down' + else: + trend_4h = 'neutral' + + # 策略权重配置(与strategy.py保持一致) + TREND_SIGNAL_WEIGHTS = { + 'macd_cross': 5, # MACD金叉/死叉 + 'ema_cross': 4, # EMA20上穿/下穿EMA50 + 'price_above_ema20': 3, # 价格在EMA20之上/下 + '4h_trend_confirmation': 2, # 4H趋势确认 + } + + # MACD金叉/死叉(权重最高) + if macd and macd['macd'] > macd['signal'] and macd['histogram'] > 0: + # MACD金叉,做多信号(需4H趋势向上或中性) + if trend_4h in ('up', 'neutral', None): + signal_strength += TREND_SIGNAL_WEIGHTS['macd_cross'] + if direction is None: + direction = 'BUY' + elif macd and macd['macd'] < macd['signal'] and macd['histogram'] < 0: + # MACD死叉,做空信号(需4H趋势向下或中性) + if trend_4h in ('down', 'neutral', None): + signal_strength += TREND_SIGNAL_WEIGHTS['macd_cross'] + if direction is None: + direction = 'SELL' + + # EMA均线系统 + 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' + 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' + + # 价格与EMA20关系 + if ema20: + if current_price > ema20: + if trend_4h in ('up', 'neutral', None) and direction == 'BUY': + signal_strength += TREND_SIGNAL_WEIGHTS['price_above_ema20'] + elif current_price < ema20: + if trend_4h in ('down', 'neutral', None) and direction == 'SELL': + signal_strength += TREND_SIGNAL_WEIGHTS['price_above_ema20'] + + # 4H趋势确认加分 + if direction and trend_4h: + if (direction == 'BUY' and trend_4h == 'up') or (direction == 'SELL' and trend_4h == 'down'): + signal_strength += TREND_SIGNAL_WEIGHTS['4h_trend_confirmation'] + elif (direction == 'BUY' and trend_4h == 'down') or (direction == 'SELL' and trend_4h == 'up'): + # 逆势信号,直接拒绝 + signal_strength = 0 + direction = None + + # 强度上限归一到 0-10 + signal_strength = max(0, min(int(signal_strength), 10)) + return { 'symbol': symbol, # 技术分析使用的价格(K线收盘价) @@ -399,7 +475,9 @@ class MarketScanner: 'ema20_4h': ema20_4h, # 4H周期EMA20,用于多周期共振 'price_4h': close_prices_4h[-1] if len(close_prices_4h) > 0 else current_price, # 4H周期当前价格 'marketRegime': market_regime, - 'signalScore': signal_score, + 'signalScore': signal_score, # 保留用于兼容性 + 'signal_strength': signal_strength, # ⚠️ 2026-01-27优化:添加真实的信号强度 + 'trend_4h': trend_4h, # 4H趋势方向 'klines': klines[-10:], # 保留最近10根K线 'klines_4h': klines_4h[-10:] if len(klines_4h) >= 10 else klines_4h # 保留最近10根4H K线 }