Simplify backtest condition
This commit is contained in:
parent
62ca822597
commit
b6c096d3bc
@ -924,19 +924,18 @@ class Backtesting:
|
|||||||
Handling of left open trades at the end of backtesting
|
Handling of left open trades at the end of backtesting
|
||||||
"""
|
"""
|
||||||
for pair in open_trades.keys():
|
for pair in open_trades.keys():
|
||||||
if len(open_trades[pair]) > 0:
|
for trade in open_trades[pair]:
|
||||||
for trade in open_trades[pair]:
|
if trade.open_order_id and trade.nr_of_successful_entries == 0:
|
||||||
if trade.open_order_id and trade.nr_of_successful_entries == 0:
|
# Ignore trade if entry-order did not fill yet
|
||||||
# Ignore trade if entry-order did not fill yet
|
continue
|
||||||
continue
|
exit_row = data[pair][-1]
|
||||||
exit_row = data[pair][-1]
|
self._exit_trade(trade, exit_row, exit_row[OPEN_IDX], trade.amount)
|
||||||
self._exit_trade(trade, exit_row, exit_row[OPEN_IDX], trade.amount)
|
trade.orders[-1].close_bt_order(exit_row[DATE_IDX].to_pydatetime(), trade)
|
||||||
trade.orders[-1].close_bt_order(exit_row[DATE_IDX].to_pydatetime(), trade)
|
|
||||||
|
|
||||||
trade.close_date = exit_row[DATE_IDX].to_pydatetime()
|
trade.close_date = exit_row[DATE_IDX].to_pydatetime()
|
||||||
trade.exit_reason = ExitType.FORCE_EXIT.value
|
trade.exit_reason = ExitType.FORCE_EXIT.value
|
||||||
trade.close(exit_row[OPEN_IDX], show_msg=False)
|
trade.close(exit_row[OPEN_IDX], show_msg=False)
|
||||||
LocalTrade.close_bt_trade(trade)
|
LocalTrade.close_bt_trade(trade)
|
||||||
|
|
||||||
def trade_slot_available(self, max_open_trades: int, open_trade_count: int) -> bool:
|
def trade_slot_available(self, max_open_trades: int, open_trade_count: int) -> bool:
|
||||||
# Always allow trades when max_open_trades is enabled.
|
# Always allow trades when max_open_trades is enabled.
|
||||||
|
Loading…
Reference in New Issue
Block a user