diff --git a/trading_system/position_manager.py b/trading_system/position_manager.py index 4d661a7..57e67fd 100644 --- a/trading_system/position_manager.py +++ b/trading_system/position_manager.py @@ -550,15 +550,18 @@ class PositionManager: atr=atr ) + # ⚠️ 2026-01-29优化:计算止损距离用于盈亏比止盈计算(确保达到3:1目标) stop_distance_for_tp = None if side == 'BUY': stop_distance_for_tp = entry_price - stop_loss_price else: stop_distance_for_tp = stop_loss_price - entry_price - + + # 如果ATR可用,使用ATR计算更准确的止损距离(用于盈亏比止盈) if atr is not None and atr > 0 and entry_price > 0: 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 take_profit_pct_margin = config.TRADING_CONFIG.get('TAKE_PROFIT_PERCENT', 0.30) diff --git a/trading_system/risk_manager.py b/trading_system/risk_manager.py index fcd9898..72d2588 100644 --- a/trading_system/risk_manager.py +++ b/trading_system/risk_manager.py @@ -867,27 +867,40 @@ class RiskManager: else: take_profit_price_price = None - # ⚠️ 2026-01-27优化:选择最终的止盈价(优先使用固定百分比止盈,更容易触发) - # 优先使用固定百分比止盈(20%),而不是ATR止盈,更容易触发,提升止盈单比例 + # ⚠️ 2026-01-29优化:优先使用基于止损距离的盈亏比止盈(确保达到3:1目标) + # 如果ATR止盈是基于止损距离×盈亏比计算的,优先使用它(确保达到3:1盈亏比) 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)) if take_profit_price_price is not None: 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优化:选择"更紧"的止盈(更接近入场价),更容易触发 - # - 做多(BUY):止盈价越高越紧 → 取最小值(更低的止盈价,更接近入场价) - # - 做空(SELL):止盈价越低越紧 → 取最大值(更高的止盈价,更接近入场价) - if side == 'BUY': - # 做多:选择更低的止盈价(更接近入场价,更容易触发) - 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] + # ⚠️ 2026-01-29优化:优先使用基于止损距离的盈亏比止盈(确保达到3:1目标) + # 如果存在基于盈亏比的止盈,优先使用它;否则选择最远的止盈(给利润更多空间,提高盈亏比) + if is_rr_based and take_profit_price_atr is not None: + # 优先使用基于止损距离的盈亏比止盈(确保达到3:1目标) + take_profit_price = take_profit_price_atr + selected_method = 'ATR盈亏比' 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] logger.info( @@ -895,7 +908,9 @@ class RiskManager: + (f"ATR={take_profit_price_atr:.4f}, " if take_profit_price_atr else "") + f"基于保证金={take_profit_price_margin:.4f}, " + (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)" ) return take_profit_price