From 9b02dc069246b4cec0c59aa8aa9b1ee32bf208cd Mon Sep 17 00:00:00 2001 From: Brook Miles Date: Thu, 27 May 2021 21:17:43 +0900 Subject: [PATCH] in backtesting, calculate trailing stop sell price as being half way between the stop loss and low --- freqtrade/optimize/backtesting.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index cbc0995aa..7c15c7ff4 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -224,6 +224,13 @@ class Backtesting: # sell at open price. return sell_row[OPEN_IDX] + if sell.sell_type == SellType.TRAILING_STOP_LOSS: + # trailing stop could potentially occur at any price between + # trade.stop_loss and candle low, so use the mid point + # to prevent extremely optimistic results with tight stops + stop_price = (trade.stop_loss + sell_row[LOW_IDX]) / 2 + return stop_price + # Set close_rate to stoploss return trade.stop_loss elif sell.sell_type == (SellType.ROI):