This commit is contained in:
薇薇安 2026-02-02 20:05:10 +08:00
parent d3f2cce922
commit 76e6e5efd0
2 changed files with 32 additions and 18 deletions

View File

@ -242,6 +242,11 @@ def _get_trading_config():
'MAX_CHANGE_PERCENT_FOR_LONG': 25, # 做多时 24h 涨跌幅超过此值则不开多(避免追大涨)
'MIN_RSI_FOR_SHORT': 30, # 做空时 RSI 低于此值则不做空(避免深超卖反弹)
'MAX_CHANGE_PERCENT_FOR_SHORT': 10, # 做空时 24h 涨跌幅超过此值则不做空24h 仍大涨时不做空)
# ===== RSI 极限反转策略(抄底/逃顶)=====
'RSI_EXTREME_REVERSE_ENABLED': True, # 开启RSI极限反转超买反空超卖反多
'RSI_EXTREME_REVERSE_ONLY_NEUTRAL_4H': False, # 允许在有趋势时反向操作例如下跌趋势中RSI超卖 -> 抄底)
'ATR_SPIKE_THRESHOLD': 2.0, # ATR异常激增阈值当前ATR / 平均ATR
'SIGNAL_STRENGTH_POSITION_MULTIPLIER': {7: 0.8, 8: 0.9, 9: 1.0, 10: 1.0}, # 信号强度分级7分80%仓位8分90%9-10分100%快速验证模式支持7-8分信号

View File

@ -405,8 +405,8 @@ class TradingStrategy:
# MACD金叉/死叉(权重最高)
if macd and macd['macd'] > macd['signal'] and macd['histogram'] > 0:
# MACD金叉做多信号严格4H趋势向上
# OPTIMIZATION: 仅允许明确向上趋势,移除 neutral 和 None避免震荡行情止损
if trend_4h == 'up':
# OPTIMIZATION: 允许明确向上趋势或中性趋势(如果是中性,后续需依靠高分信号确认)
if trend_4h in ('up', 'neutral'):
# OPTIMIZATION: 添加 RSI 过滤,避免追高
if rsi is None or rsi < 70:
signal_strength += TREND_SIGNAL_WEIGHTS['macd_cross']
@ -416,12 +416,12 @@ class TradingStrategy:
else:
reasons.append(f"MACD金叉但RSI超买({rsi:.1f}),禁止追多")
else:
reasons.append(f"MACD金叉但4H趋势不明确({trend_4h}),禁止开仓")
reasons.append(f"MACD金叉但4H趋势相反({trend_4h}),禁止逆势")
elif macd and macd['macd'] < macd['signal'] and macd['histogram'] < 0:
# MACD死叉做空信号严格4H趋势向下
# OPTIMIZATION: 允许明确向下趋势
if trend_4h == 'down':
# OPTIMIZATION: 允许明确向下趋势或中性趋势
if trend_4h in ('down', 'neutral'):
# OPTIMIZATION: 添加 RSI 过滤,避免杀跌
if rsi is None or rsi > 30:
signal_strength += TREND_SIGNAL_WEIGHTS['macd_cross']
@ -431,13 +431,13 @@ class TradingStrategy:
else:
reasons.append(f"MACD死叉但RSI超卖({rsi:.1f}),禁止追空")
else:
reasons.append(f"MACD死叉但4H趋势不明确({trend_4h}),禁止开仓")
reasons.append(f"MACD死叉但4H趋势相反({trend_4h}),禁止逆势")
# EMA均线系统
if ema20 and ema50:
if current_price > ema20 > ema50: # 上升趋势
# OPTIMIZATION: 允许明确向上趋势
if trend_4h == 'up':
# OPTIMIZATION: 允许明确向上趋势或中性趋势
if trend_4h in ('up', 'neutral'):
# OPTIMIZATION: 添加 RSI 过滤
if rsi is None or rsi < 70:
signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross']
@ -445,10 +445,10 @@ class TradingStrategy:
if direction is None:
direction = 'BUY'
else:
reasons.append(f"1H均线向上但4H趋势不明确({trend_4h}),禁止开仓")
reasons.append(f"1H均线向上但4H趋势相反({trend_4h}),禁止逆势")
elif current_price < ema20 < ema50: # 下降趋势
# OPTIMIZATION: 允许明确向下趋势
if trend_4h == 'down':
# OPTIMIZATION: 允许明确向下趋势或中性趋势
if trend_4h in ('down', 'neutral'):
# OPTIMIZATION: 添加 RSI 过滤
if rsi is None or rsi > 30:
signal_strength += TREND_SIGNAL_WEIGHTS['ema_cross']
@ -456,16 +456,16 @@ class TradingStrategy:
if direction is None:
direction = 'SELL'
else:
reasons.append(f"1H均线向下但4H趋势不明确({trend_4h}),禁止开仓")
reasons.append(f"1H均线向下但4H趋势相反({trend_4h}),禁止逆势")
# 价格与EMA20关系
if ema20:
if current_price > ema20:
if trend_4h == 'up' and direction == 'BUY':
if trend_4h in ('up', 'neutral') and direction == 'BUY':
signal_strength += TREND_SIGNAL_WEIGHTS['price_above_ema20']
reasons.append("价格在EMA20之上")
elif current_price < ema20:
if trend_4h == 'down' and direction == 'SELL':
if trend_4h in ('down', 'neutral') and direction == 'SELL':
signal_strength += TREND_SIGNAL_WEIGHTS['price_above_ema20']
reasons.append("价格在EMA20之下")
@ -588,17 +588,26 @@ class TradingStrategy:
# 提升胜率4H趋势中性时不做自动交易只保留推荐/观察)
# 经验上,中性趋势下“趋势跟踪”信号更容易被来回扫损,导致胜率显著降低与交易次数激增。
allow_neutral = bool(config.TRADING_CONFIG.get("AUTO_TRADE_ALLOW_4H_NEUTRAL", False))
if (trend_4h == 'neutral') and (not allow_neutral):
# 稳健优化:如果信号非常强(>=8即使4H中性也允许尝试通常意味着突破初期
is_strong_signal = signal_strength >= 8
if (trend_4h == 'neutral') and (not allow_neutral) and (not is_strong_signal):
if should_trade:
reasons.append("❌ 4H趋势中性为提升胜率仅生成推荐不自动交易")
reasons.append("❌ 4H趋势中性且信号强度不足(<8跳过自动交易")
should_trade = False
# 如果信号方向与4H趋势相反直接拒绝交易所有模式
if direction and trend_4h:
# 如果信号方向与4H趋势相反直接拒绝交易除非是RSI极限反转策略
if direction and trend_4h and not reversed_by_rsi:
if (direction == 'BUY' and trend_4h == 'down') or (direction == 'SELL' and trend_4h == 'up'):
should_trade = False
reasons.append("❌ 禁止逆4H趋势交易")
# 对于 RSI 极限反转策略,虽然允许逆势,但增加额外提示
if direction and trend_4h and reversed_by_rsi:
if (direction == 'BUY' and trend_4h == 'down'):
reasons.append("⚠️ 逆4H趋势抄底RSI超卖反转")
elif (direction == 'SELL' and trend_4h == 'up'):
reasons.append("⚠️ 逆4H趋势逃顶RSI超买反转")
# 只在“真的强度不足”时追加该原因;避免出现“强度>=阈值但被其它过滤挡住”仍提示强度不足
if direction and (signal_strength < min_signal_strength):
reasons.append(f"信号强度不足({signal_strength}/10需要≥{min_signal_strength})")