Attempt fix for #6261
This commit is contained in:
parent
acd7f26a9d
commit
30f6dbfc40
@ -357,6 +357,15 @@ class Backtesting:
|
|||||||
# use Open rate if open_rate > calculated sell rate
|
# use Open rate if open_rate > calculated sell rate
|
||||||
return sell_row[OPEN_IDX]
|
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
|
# Use the maximum between close_rate and low as we
|
||||||
# cannot sell outside of a candle.
|
# cannot sell outside of a candle.
|
||||||
# Applies when a new ROI setting comes in place and the whole candle is above that.
|
# 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.close_date = sell_candle_time
|
||||||
|
|
||||||
trade_dur = int((trade.close_date_utc - trade.open_date_utc).total_seconds() // 60)
|
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
|
# call the custom exit price,with default value as previous closerate
|
||||||
current_profit = trade.calc_profit_ratio(closerate)
|
current_profit = trade.calc_profit_ratio(closerate)
|
||||||
order_type = self.strategy.order_types['sell']
|
order_type = self.strategy.order_types['sell']
|
||||||
|
@ -562,9 +562,9 @@ tc35 = BTContainer(data=[
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Test 36: Custom-entry-price around candle low
|
# Test 36: Custom-entry-price around candle low
|
||||||
# Causes immediate ROI exit. This is currently expected behavior (#6261)
|
# Would cause immediate ROI exit, but since the trade was entered
|
||||||
# https://github.com/freqtrade/freqtrade/issues/6261
|
# below open, we treat this as cheating, and delay the sell by 1 candle.
|
||||||
# But may change at a later point.
|
# details: https://github.com/freqtrade/freqtrade/issues/6261
|
||||||
tc36 = BTContainer(data=[
|
tc36 = BTContainer(data=[
|
||||||
# D O H L C V B S BT
|
# D O H L C V B S BT
|
||||||
[0, 5000, 5050, 4950, 5000, 6172, 1, 0],
|
[0, 5000, 5050, 4950, 5000, 6172, 1, 0],
|
||||||
@ -574,7 +574,7 @@ tc36 = BTContainer(data=[
|
|||||||
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]],
|
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]],
|
||||||
stop_loss=-0.10, roi={"0": 0.01}, profit_perc=0.01,
|
stop_loss=-0.10, roi={"0": 0.01}, profit_perc=0.01,
|
||||||
custom_entry_price=4952,
|
custom_entry_price=4952,
|
||||||
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=1)]
|
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=2)]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user