This commit is contained in:
薇薇安 2026-01-29 18:45:32 +08:00
parent f1a82f53e0
commit 53396adf26
2 changed files with 36 additions and 18 deletions

View File

@ -550,15 +550,18 @@ class PositionManager:
atr=atr atr=atr
) )
# ⚠️ 2026-01-29优化计算止损距离用于盈亏比止盈计算确保达到3:1目标
stop_distance_for_tp = None stop_distance_for_tp = None
if side == 'BUY': if side == 'BUY':
stop_distance_for_tp = entry_price - stop_loss_price stop_distance_for_tp = entry_price - stop_loss_price
else: else:
stop_distance_for_tp = stop_loss_price - entry_price stop_distance_for_tp = stop_loss_price - entry_price
# 如果ATR可用使用ATR计算更准确的止损距离用于盈亏比止盈
if atr is not None and atr > 0 and entry_price > 0: if atr is not None and atr > 0 and entry_price > 0:
atr_percent = atr / entry_price atr_percent = atr / entry_price
atr_multiplier = config.TRADING_CONFIG.get('ATR_STOP_LOSS_MULTIPLIER', 2.5) # 默认2.5,放宽止损提升胜率 atr_multiplier = config.TRADING_CONFIG.get('ATR_STOP_LOSS_MULTIPLIER', 2.0) # 2026-01-29优化默认2.0
# 使用ATR计算的止损距离更准确用于盈亏比止盈
stop_distance_for_tp = entry_price * atr_percent * atr_multiplier stop_distance_for_tp = entry_price * atr_percent * atr_multiplier
take_profit_pct_margin = config.TRADING_CONFIG.get('TAKE_PROFIT_PERCENT', 0.30) take_profit_pct_margin = config.TRADING_CONFIG.get('TAKE_PROFIT_PERCENT', 0.30)

View File

@ -867,27 +867,40 @@ class RiskManager:
else: else:
take_profit_price_price = None take_profit_price_price = None
# ⚠️ 2026-01-27优化选择最终的止盈价优先使用固定百分比止盈更容易触发 # ⚠️ 2026-01-29优化优先使用基于止损距离的盈亏比止盈确保达到3:1目标
# 优先使用固定百分比止盈20%而不是ATR止盈更容易触发提升止盈单比例 # 如果ATR止盈是基于止损距离×盈亏比计算的优先使用它确保达到3:1盈亏比
candidate_prices = [] candidate_prices = []
# 优先添加固定百分比止盈(更容易触发)
# 检查是否是基于盈亏比计算的通过details判断
is_rr_based = (atr_tp_details and atr_tp_details.get('method') == 'ATR止损距离×盈亏比')
# 优先添加基于止损距离的盈亏比止盈如果可用确保达到3:1目标
if take_profit_price_atr is not None:
if is_rr_based:
candidate_prices.append(('ATR盈亏比', take_profit_price_atr))
else:
# ATR倍数止盈作为备选
candidate_prices.append(('ATR倍数', take_profit_price_atr))
# 添加固定百分比止盈(作为备选)
candidate_prices.append(('保证金', take_profit_price_margin)) candidate_prices.append(('保证金', take_profit_price_margin))
if take_profit_price_price is not None: if take_profit_price_price is not None:
candidate_prices.append(('价格百分比', take_profit_price_price)) candidate_prices.append(('价格百分比', take_profit_price_price))
# ATR止盈作为备选如果比固定百分比更紧则使用
if take_profit_price_atr is not None:
candidate_prices.append(('ATR', take_profit_price_atr))
# ⚠️ 2026-01-27优化选择"更紧"的止盈(更接近入场价),更容易触发 # ⚠️ 2026-01-29优化优先使用基于止损距离的盈亏比止盈确保达到3:1目标
# - 做多(BUY):止盈价越高越紧 → 取最小值(更低的止盈价,更接近入场价) # 如果存在基于盈亏比的止盈,优先使用它;否则选择最远的止盈(给利润更多空间,提高盈亏比)
# - 做空(SELL):止盈价越低越紧 → 取最大值(更高的止盈价,更接近入场价) if is_rr_based and take_profit_price_atr is not None:
if side == 'BUY': # 优先使用基于止损距离的盈亏比止盈确保达到3:1目标
# 做多:选择更低的止盈价(更接近入场价,更容易触发) take_profit_price = take_profit_price_atr
take_profit_price = min(p[1] for p in candidate_prices) selected_method = 'ATR盈亏比'
selected_method = [p[0] for p in candidate_prices if p[1] == take_profit_price][0]
else: else:
# 做空:选择更高的止盈价(更接近入场价,更容易触发) # 如果没有基于盈亏比的止盈,选择最远的止盈(给利润更多空间,提高盈亏比)
take_profit_price = max(p[1] for p in candidate_prices) if side == 'BUY':
# 做多:选择更高的止盈价(更远,给利润更多空间)
take_profit_price = max(p[1] for p in candidate_prices)
else:
# 做空:选择更低的止盈价(更远,给利润更多空间)
take_profit_price = min(p[1] for p in candidate_prices)
selected_method = [p[0] for p in candidate_prices if p[1] == take_profit_price][0] selected_method = [p[0] for p in candidate_prices if p[1] == take_profit_price][0]
logger.info( logger.info(
@ -895,7 +908,9 @@ class RiskManager:
+ (f"ATR={take_profit_price_atr:.4f}, " if take_profit_price_atr else "") + (f"ATR={take_profit_price_atr:.4f}, " if take_profit_price_atr else "")
+ f"基于保证金={take_profit_price_margin:.4f}, " + f"基于保证金={take_profit_price_margin:.4f}, "
+ (f"基于价格={take_profit_price_price:.4f}, " if take_profit_price_price else "") + (f"基于价格={take_profit_price_price:.4f}, " if take_profit_price_price else "")
+ f"最终止盈={take_profit_price:.4f} (使用{selected_method}, 取更紧), " + f"最终止盈={take_profit_price:.4f} (使用{selected_method}"
+ (", 确保3:1盈亏比" if is_rr_based else ", 选择最远止盈")
+ "), "
+ f"止盈金额={take_profit_amount:.4f} USDT ({take_profit_percent*100:.1f}% of margin)" + f"止盈金额={take_profit_amount:.4f} USDT ({take_profit_percent*100:.1f}% of margin)"
) )
return take_profit_price return take_profit_price