From e4cca631638e0380fbfd23a88387d46d6038800d Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 8 Nov 2021 06:44:55 +0100 Subject: [PATCH] Align sell_reason assignment location trade mode sets it after "exit confirmation" - so should backtesting detected in #5828 --- freqtrade/optimize/backtesting.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 2f074500f..014ec8afc 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -362,16 +362,6 @@ class Backtesting: if sell.sell_flag: trade.close_date = sell_candle_time - trade.sell_reason = sell.sell_reason - - # Checks and adds an exit tag, after checking that the length of the - # sell_row has the length for an exit tag column - if( - len(sell_row) > EXIT_TAG_IDX - and sell_row[EXIT_TAG_IDX] is not None - and len(sell_row[EXIT_TAG_IDX]) > 0 - ): - trade.sell_reason = sell_row[EXIT_TAG_IDX] trade_dur = int((trade.close_date_utc - trade.open_date_utc).total_seconds() // 60) closerate = self._get_close_rate(sell_row, trade, sell, trade_dur) @@ -386,6 +376,17 @@ class Backtesting: current_time=sell_candle_time): return None + trade.sell_reason = sell.sell_reason + + # Checks and adds an exit tag, after checking that the length of the + # sell_row has the length for an exit tag column + if( + len(sell_row) > EXIT_TAG_IDX + and sell_row[EXIT_TAG_IDX] is not None + and len(sell_row[EXIT_TAG_IDX]) > 0 + ): + trade.sell_reason = sell_row[EXIT_TAG_IDX] + trade.close(closerate, show_msg=False) return trade