diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index a76138bbf..5aa3974d0 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -534,7 +534,7 @@ class Backtesting: if sell.sell_flag: trade.close_date = sell_candle_time - trade_dur = int((trade.close_date_utc - trade.open_date_utc).total_seconds() // 60) + trade_dur = int((trade.close_date_utc - trade.filled_date_utc).total_seconds() // 60) try: closerate = self._get_close_rate(sell_row, trade, sell, trade_dur) except ValueError: diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index b80d75dc0..3836424c4 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -366,6 +366,10 @@ class LocalTrade(): else: return self.amount + @property + def filled_date_utc(self): + return self.select_order('buy', is_open=False).order_filled_date.replace(tzinfo=timezone.utc) + @property def open_date_utc(self): return self.open_date.replace(tzinfo=timezone.utc)