use sell_row.open also when the active ROI value just changed
This commit is contained in:
@@ -273,19 +273,26 @@ class Backtesting:
|
||||
roi_entry, roi = self.strategy.min_roi_reached_entry(trade_dur)
|
||||
if roi is not None:
|
||||
if roi == -1 and roi_entry % self.timeframe_mins == 0:
|
||||
# When forceselling with ROI=-1, the roi-entry will always be "on the entry".
|
||||
# If that entry is a multiple of the timeframe (so on open)
|
||||
# When forceselling with ROI=-1, the roi time will always be equal to trade_dur.
|
||||
# If that entry is a multiple of the timeframe (so on candle open)
|
||||
# - we'll use open instead of close
|
||||
return sell_row.open
|
||||
|
||||
# - (Expected abs profit + open_rate + open_fee) / (fee_close -1)
|
||||
closerate = - (trade.open_rate * roi + trade.open_rate *
|
||||
(1 + trade.fee_open)) / (trade.fee_close - 1)
|
||||
close_rate = - (trade.open_rate * roi + trade.open_rate *
|
||||
(1 + trade.fee_open)) / (trade.fee_close - 1)
|
||||
|
||||
# Use the maximum between closerate and low as we
|
||||
if (trade_dur > 0 and trade_dur == roi_entry
|
||||
and roi_entry % self.timeframe_mins == 0
|
||||
and sell_row.open > close_rate):
|
||||
# new ROI entry came into effect.
|
||||
# use Open rate if open_rate > calculated sell rate
|
||||
return sell_row.open
|
||||
|
||||
# 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.
|
||||
return max(closerate, sell_row.low)
|
||||
return max(close_rate, sell_row.low)
|
||||
|
||||
else:
|
||||
# This should not be reached...
|
||||
|
Reference in New Issue
Block a user