edit backtest_loop to check exit if trade has open position

This commit is contained in:
Axel-CH 2024-04-14 00:16:55 -04:00
parent 65654a4a44
commit 3d67e0893a
2 changed files with 20 additions and 1 deletions

View File

@ -1181,7 +1181,7 @@ class Backtesting:
self.wallets.update()
# 4. Create exit orders (if any)
if not trade.has_open_orders:
if trade.has_open_position:
self._check_trade_exit(trade, row, current_time) # Place exit order if necessary
# 5. Process exit orders.

View File

@ -544,6 +544,25 @@ class LocalTrade:
]
return len(open_orders_wo_sl) > 0
@property
def has_open_position(self) -> bool:
"""
True if there is an open position for this trade
"""
entry_orders = [
o for o in self.orders
if o.ft_order_side == self.entry_side
]
entry_orders_filled_qty = sum(eo.filled for eo in entry_orders)
exit_orders = [
o for o in self.orders
if o.ft_order_side == self.exit_side
]
exit_orders_filled_qty = sum(eo.filled for eo in exit_orders)
return (entry_orders_filled_qty - exit_orders_filled_qty) > 0
@property
def open_sl_orders(self) -> List[Order]:
"""