feat(market_scanner, strategy): 引入回退信号逻辑以优化信号处理
在市场扫描和交易策略中增加了回退信号逻辑,当信号强度为零且方向未明确时,采用RSI、MACD和布林带的综合信号进行判断,避免长期无推荐。这一改动旨在提升策略的灵活性与可用性,确保在市场波动时仍能提供有效的交易建议。
This commit is contained in:
parent
5b2adb0b62
commit
0f0aa1bf5d
|
|
@ -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:
|
||||
# 只有在方向明确且信号强度达到最小门槛时,才记录趋势状态
|
||||
|
|
|
|||
|
|
@ -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 极端反向(超买反空/超卖反多)=====
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user