Attempt fix for #6261

This commit is contained in:
Matthias
2022-02-14 20:02:38 +01:00
parent acd7f26a9d
commit 30f6dbfc40
2 changed files with 17 additions and 5 deletions

View File

@@ -357,6 +357,15 @@ class Backtesting:
# use Open rate if open_rate > calculated sell rate
return sell_row[OPEN_IDX]
if (
trade_dur == 0
and trade.open_rate < sell_row[OPEN_IDX] # trade-open > open_rate
and sell_row[OPEN_IDX] > sell_row[CLOSE_IDX] # Red candle
):
# ROI on opening candles with custom pricing can only
# trigger if the entry was at Open or lower.
# details: https: // github.com/freqtrade/freqtrade/issues/6261
raise ValueError("Opening candle ROI on red candles.")
# 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.
@@ -414,7 +423,10 @@ class Backtesting:
trade.close_date = sell_candle_time
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)
try:
closerate = self._get_close_rate(sell_row, trade, sell, trade_dur)
except ValueError:
return None
# call the custom exit price,with default value as previous closerate
current_profit = trade.calc_profit_ratio(closerate)
order_type = self.strategy.order_types['sell']