From 68ac8008ecf2eae00a01d6ee2e21f8703fb9606a Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 4 Dec 2021 14:14:22 +0100 Subject: [PATCH] Call custom_exit_price only for sell_signal and custom_sell --- docs/bot-basics.md | 2 +- docs/strategy-callbacks.md | 1 + freqtrade/optimize/backtesting.py | 12 +++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/bot-basics.md b/docs/bot-basics.md index 67cc5cd1b..0b9f7b67c 100644 --- a/docs/bot-basics.md +++ b/docs/bot-basics.md @@ -59,7 +59,7 @@ This loop will be repeated again and again until the bot is stopped. * Call `custom_entry_price()` (if implemented in the strategy) to determine entry price (Prices are moved to be within the opening candle). * Determine stake size by calling the `custom_stake_amount()` callback. * Call `custom_stoploss()` and `custom_sell()` to find custom exit points. - * Call `custom_exit_price()` to determine exit price (Prices are moved to be within the closing candle). + * For sells based on sell-signal and custom-sell: Call `custom_exit_price()` to determine exit price (Prices are moved to be within the closing candle). * Generate backtest report output diff --git a/docs/strategy-callbacks.md b/docs/strategy-callbacks.md index 895e50425..11032433d 100644 --- a/docs/strategy-callbacks.md +++ b/docs/strategy-callbacks.md @@ -390,6 +390,7 @@ class AwesomeStrategy(IStrategy): !!! Warning "Backtesting" While Custom prices are supported in backtesting (starting with 2021.12), prices will be moved to within the candle's high/low prices. This behavior is currently being tested, and might be changed at a later point. + `custom_exit_price()` is only called for sells of type Sell_signal and Custom sell. All other sell-types will use regular backtesting prices. ## Custom order timeout rules diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index a561502fa..55461b3e1 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -365,11 +365,13 @@ class Backtesting: closerate = self._get_close_rate(sell_row, trade, sell, trade_dur) # call the custom exit price,with default value as previous closerate current_profit = trade.calc_profit_ratio(closerate) - closerate = strategy_safe_wrapper(self.strategy.custom_exit_price, - default_retval=closerate)( - pair=trade.pair, trade=trade, - current_time=sell_row[DATE_IDX], - proposed_rate=closerate, current_profit=current_profit) + if sell.sell_type in (SellType.SELL_SIGNAL, SellType.CUSTOM_SELL): + # Custom exit pricing only for sell-signals + closerate = strategy_safe_wrapper(self.strategy.custom_exit_price, + default_retval=closerate)( + pair=trade.pair, trade=trade, + current_time=sell_row[DATE_IDX], + proposed_rate=closerate, current_profit=current_profit) # Use the maximum between close_rate and low as we cannot sell outside of a candle. # Applies when a new ROI setting comes in place and the whole candle is above that. closerate = min(max(closerate, sell_row[LOW_IDX]), sell_row[HIGH_IDX])