From 18fd3bb3332f2d50401fa6b428d073615b02db7e Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 15 May 2022 15:30:57 +0200 Subject: [PATCH] Update stoploss handling for entry-order adjustment --- freqtrade/optimize/backtesting.py | 6 +----- freqtrade/persistence/trade_model.py | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index f439e4e63..621812b0a 100755 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -780,8 +780,6 @@ class Backtesting: # interest_rate=interest_rate, orders=[], ) - elif trade.nr_of_successful_entries == 0: - trade.open_rate = propose_rate trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True) @@ -814,11 +812,11 @@ class Backtesting: remaining=amount, cost=stake_amount + trade.fee_open, ) + trade.orders.append(order) if pos_adjust and self._get_order_filled(order.price, row): order.close_bt_order(current_time, trade) else: trade.open_order_id = str(self.order_id_counter) - trade.orders.append(order) trade.recalc_trade_from_orders() return trade @@ -942,8 +940,6 @@ class Backtesting: requested_rate=requested_rate, requested_stake=(order.remaining * order.price), direction='short' if trade.is_short else 'long') - trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, - initial=False, refresh=True) else: # assumption: there can't be multiple open entry orders at any given time return (trade.nr_of_successful_entries == 0) diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index bbdeeef47..358e776e3 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -153,6 +153,7 @@ class Order(_DECL_BASE): and len(trade.select_filled_orders(trade.entry_side)) == 1): trade.open_rate = self.price trade.recalc_open_trade_value() + trade.adjust_stop_loss(trade.open_rate, trade.stop_loss_pct, refresh=True) @staticmethod def update_orders(orders: List['Order'], order: Dict[str, Any]): @@ -502,7 +503,7 @@ class LocalTrade(): if initial and not (self.stop_loss is None or self.stop_loss == 0): # Don't modify if called with initial and nothing to do return - refresh = False if self.nr_of_successful_entries > 0 else refresh + refresh = True if refresh and self.nr_of_successful_entries == 1 else False leverage = self.leverage or 1.0 if self.is_short: