This commit is contained in:
薇薇安 2026-01-25 10:59:34 +08:00
parent 04f222875a
commit 10fd7a7d60

View File

@ -681,14 +681,17 @@ class RiskManager:
if stop_loss_price_price is not None:
candidate_prices.append(('价格百分比', stop_loss_price_price))
# 选择“更宽松/更远”的止损:
# - 做多(BUY):止损越低越宽松 → 取最小值
# - 做空(SELL):止损越高越宽松 → 取最大值
# ⚠️ 修复:选择"更紧的止损"(更接近入场价),保护资金
# - 做多(BUY):止损价越低越紧(更接近入场价)→ 取最大值(更高的止损价,更接近入场价)
# - 做空(SELL):止损价越高越紧(更接近入场价)→ 取最小值(更低的止损价,更接近入场价)
# 注意:做空时,止损价高于入场价,所以"更紧"意味着"更小的止损价"(更接近入场价)
if side == 'BUY':
stop_loss_price = min(p[1] for p in candidate_prices)
# 做多:止损价越低越紧 → 取最大值(更高的止损价,更接近入场价)
stop_loss_price = max(p[1] for p in candidate_prices)
selected_method = [p[0] for p in candidate_prices if p[1] == stop_loss_price][0]
else:
stop_loss_price = max(p[1] for p in candidate_prices)
# 做空:止损价越高越紧 → 取最小值(更低的止损价,更接近入场价)
stop_loss_price = min(p[1] for p in candidate_prices)
selected_method = [p[0] for p in candidate_prices if p[1] == stop_loss_price][0]
# 如果提供了技术分析数据,计算技术止损(允许更紧的止损,但需要在保证金止损范围内)