mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 02:12:01 +00:00
edit backtest_loop to check exit if trade has open position
This commit is contained in:
parent
65654a4a44
commit
3d67e0893a
|
@ -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.
|
||||
|
|
|
@ -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]:
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user