a
This commit is contained in:
parent
d3f2cce922
commit
76e6e5efd0
|
|
@ -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分信号)
|
||||
|
||||
|
|
|
|||
|
|
@ -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})")
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user