From 2eac23a15f7c3b1d032fa19bd233da0840fcbf30 Mon Sep 17 00:00:00 2001 From: Brook Miles Date: Sat, 15 May 2021 15:38:51 +0900 Subject: [PATCH] if stoploss price is above the candle high, set it to candle open instead. this can occur if stoploss had previously been reached but the sell was prevented by `confirm_trade_exit` --- freqtrade/optimize/backtesting.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index e057d8189..689fb9516 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -218,6 +218,12 @@ class Backtesting: """ # Special handling if high or low hit STOP_LOSS or ROI if sell.sell_type in (SellType.STOP_LOSS, SellType.TRAILING_STOP_LOSS): + if trade.stop_loss > sell_row[HIGH_IDX]: + # our stoploss was already higher than candle high, + # possibly due to a cancelled trade exit. + # sell at open price. + return sell_row[OPEN_IDX] + # Set close_rate to stoploss return trade.stop_loss elif sell.sell_type == (SellType.ROI):