Update interface.py

Changed The should_sell() method, to handle the case where both ROI and trailing stoploss are reached in backtest.
This commit is contained in:
radwayne 2020-11-06 13:56:46 +01:00 committed by GitHub
parent b8f6f09de8
commit 8e03fee868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -475,16 +475,27 @@ class IStrategy(ABC):
stoplossflag = self.stop_loss_reached(current_rate=current_rate, trade=trade,
current_time=date, current_profit=current_profit,
force_stoploss=force_stoploss, high=high)
if stoplossflag.sell_flag:
logger.debug(f"{trade.pair} - Stoploss hit. sell_flag=True, "
f"sell_type={stoplossflag.sell_type}")
return stoplossflag
# Set current rate to high for backtesting sell
current_rate = high or rate
current_profit = trade.calc_profit_ratio(current_rate)
config_ask_strategy = self.config.get('ask_strategy', {})
roi_reached = self.min_roi_reached(trade=trade, current_profit=current_profit,
current_time=date)
if stoplossflag.sell_flag:
# When backtesting, in the case of trailing_stop_loss,
# make sure we don't make a profit higher than ROI.
if stoplossflag.sell_type == SellType.TRAILING_STOP_LOSS and roi_reached:
logger.debug(f"{trade.pair} - Required profit reached. sell_flag=True, "
f"sell_type=SellType.ROI")
return SellCheckTuple(sell_flag=True, sell_type=SellType.ROI)
logger.debug(f"{trade.pair} - Stoploss hit. sell_flag=True, "
f"sell_type={stoplossflag.sell_type}")
return stoplossflag
if buy and config_ask_strategy.get('ignore_roi_if_buy_signal', False):
# This one is noisy, commented out
@ -492,7 +503,7 @@ class IStrategy(ABC):
return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE)
# Check if minimal roi has been reached and no longer in buy conditions (avoiding a fee)
if self.min_roi_reached(trade=trade, current_profit=current_profit, current_time=date):
if roi_reached:
logger.debug(f"{trade.pair} - Required profit reached. sell_flag=True, "
f"sell_type=SellType.ROI")
return SellCheckTuple(sell_flag=True, sell_type=SellType.ROI)