Merge pull request #3929 from radwayne/roi_trailing_backtest
change backtesting behaviour if roi and trailing-stop happen at the same time
This commit is contained in:
@@ -476,40 +476,44 @@ class IStrategy(ABC):
|
||||
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', {})
|
||||
|
||||
if buy and config_ask_strategy.get('ignore_roi_if_buy_signal', False):
|
||||
# This one is noisy, commented out
|
||||
# logger.debug(f"{trade.pair} - Buy signal still active. sell_flag=False")
|
||||
return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE)
|
||||
# if buy signal and ignore_roi is set, we don't need to evaluate min_roi.
|
||||
roi_reached = (not (buy and config_ask_strategy.get('ignore_roi_if_buy_signal', False))
|
||||
and self.min_roi_reached(trade=trade, current_profit=current_profit,
|
||||
current_time=date))
|
||||
|
||||
# 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 config_ask_strategy.get('sell_profit_only', False) and trade.calc_profit(rate=rate) <= 0:
|
||||
# Negative profits and sell_profit_only - ignore sell signal
|
||||
sell_signal = False
|
||||
else:
|
||||
sell_signal = sell and not buy and config_ask_strategy.get('use_sell_signal', True)
|
||||
# TODO: return here if sell-signal should be favored over ROI
|
||||
|
||||
# Start evaluations
|
||||
# Sequence:
|
||||
# ROI (if not stoploss)
|
||||
# Sell-signal
|
||||
# Stoploss
|
||||
if roi_reached and stoplossflag.sell_type != SellType.STOP_LOSS:
|
||||
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)
|
||||
|
||||
if config_ask_strategy.get('sell_profit_only', False):
|
||||
# This one is noisy, commented out
|
||||
# logger.debug(f"{trade.pair} - Checking if trade is profitable...")
|
||||
if trade.calc_profit(rate=rate) <= 0:
|
||||
# This one is noisy, commented out
|
||||
# logger.debug(f"{trade.pair} - Trade is not profitable. sell_flag=False")
|
||||
return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE)
|
||||
|
||||
if sell and not buy and config_ask_strategy.get('use_sell_signal', True):
|
||||
if sell_signal:
|
||||
logger.debug(f"{trade.pair} - Sell signal received. sell_flag=True, "
|
||||
f"sell_type=SellType.SELL_SIGNAL")
|
||||
return SellCheckTuple(sell_flag=True, sell_type=SellType.SELL_SIGNAL)
|
||||
|
||||
if stoplossflag.sell_flag:
|
||||
|
||||
logger.debug(f"{trade.pair} - Stoploss hit. sell_flag=True, "
|
||||
f"sell_type={stoplossflag.sell_type}")
|
||||
return stoplossflag
|
||||
|
||||
# This one is noisy, commented out...
|
||||
# logger.debug(f"{trade.pair} - No sell signal. sell_flag=False")
|
||||
return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE)
|
||||
|
Reference in New Issue
Block a user