From fc60c0df1990ae726cf08453169b87e597ec2ee0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 14 Aug 2023 16:00:33 +0200 Subject: [PATCH] Add call to stoploss-adjust for backtesting --- freqtrade/optimize/backtesting.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index bdd04ba7f..6a3e1949c 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -578,6 +578,11 @@ class Backtesting: """ Rate is within candle, therefore filled""" return row[LOW_IDX] <= rate <= row[HIGH_IDX] + def _call_adjust_stop(self, current_date: datetime, trade: Trade, current_rate: float): + profit = trade.calc_profit_ratio(current_rate) + self.strategy.ft_stoploss_adjust(current_rate, trade, current_date, profit, 0, + after_fill=True) + def _try_close_open_order( self, order: Optional[Order], trade: LocalTrade, current_date: datetime, row: Tuple) -> bool: @@ -588,6 +593,9 @@ class Backtesting: if order and self._get_order_filled(order.ft_price, row): order.close_bt_order(current_date, trade) trade.open_order_id = None + if not (order.ft_order_side == trade.exit_side and order.safe_amount == trade.amount): + self._call_adjust_stop(current_date, trade, order.ft_price) + # pass return True return False