改进自监测机制:仅在加仓到5个网格后才触发止盈/止损,保证有足够的持仓
This commit is contained in:
parent
056855f0da
commit
5a927de07c
@ -211,6 +211,7 @@ class GridManager:
|
||||
)
|
||||
self.is_completed = False # GridManager 是否完结
|
||||
self.completion_reason: Optional[str] = None # 完结原因 (take_profit / stop_loss)
|
||||
self.min_grids_for_exit = 5 # 至少加仓到5个网格才能触发止盈/止损
|
||||
|
||||
def update_state(self, current_price: float, candle_index: int) -> None:
|
||||
"""
|
||||
@ -242,14 +243,17 @@ class GridManager:
|
||||
file=sys.stderr, flush=True)
|
||||
|
||||
# ✅ 自监测:检查是否需要止盈/止损
|
||||
# 仅在加仓超过最低网格数时才触发,保证有足够的持仓
|
||||
if not self.is_completed and self.total_quantity > 0:
|
||||
filled_count = sum(1 for gs in self.grid_states.values() if gs.status == "filled")
|
||||
if filled_count >= self.min_grids_for_exit:
|
||||
exit_reason = self.monitor.get_exit_reason(current_price, self.avg_entry_price)
|
||||
if exit_reason:
|
||||
self.is_completed = True
|
||||
self.completion_reason = exit_reason
|
||||
profit_pct = (current_price - self.avg_entry_price) / self.avg_entry_price * 100
|
||||
print(f"[GridManager] {self.pair} 自监测触发✅ - 原因: {exit_reason}, "
|
||||
f"利润: {profit_pct:.2f}%, 当前价: {current_price:.2f}",
|
||||
f"利润: {profit_pct:.2f}%, 当前价: {current_price:.2f}, 网格数: {filled_count}",
|
||||
file=sys.stderr, flush=True)
|
||||
|
||||
def apply_adjustment(self, adjustment: PositionRecord) -> None:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user