Improve handling of None values from custom_stoploss

This commit is contained in:
Matthias 2023-08-14 16:46:25 +02:00
parent ddf79088fb
commit 070a1990e8
2 changed files with 12 additions and 11 deletions

View File

@ -578,10 +578,10 @@ class Backtesting:
""" Rate is within candle, therefore filled"""
return row[LOW_IDX] <= rate <= row[HIGH_IDX]
def _call_adjust_stop(self, current_date: datetime, trade: Trade, current_rate: float):
def _call_adjust_stop(self, current_date: datetime, trade: LocalTrade, current_rate: float):
profit = trade.calc_profit_ratio(current_rate)
self.strategy.ft_stoploss_adjust(current_rate, trade, current_date, profit, 0,
after_fill=True)
self.strategy.ft_stoploss_adjust(current_rate, trade, # type: ignore
current_date, profit, 0, after_fill=True)
def _try_close_open_order(
self, order: Optional[Order], trade: LocalTrade, current_date: datetime,

View File

@ -1188,15 +1188,16 @@ class IStrategy(ABC, HyperStrategyMixin):
bound = (low if trade.is_short else high)
bound_profit = current_profit if not bound else trade.calc_profit_ratio(bound)
if self.use_custom_stoploss and dir_correct:
stop_loss_value = strategy_safe_wrapper(self.custom_stoploss, default_retval=None,
supress_error=True
)(pair=trade.pair, trade=trade,
current_time=current_time,
current_rate=(bound or current_rate),
current_profit=bound_profit,
after_fill=after_fill)
stop_loss_value_custom = strategy_safe_wrapper(
self.custom_stoploss, default_retval=None, supress_error=True
)(pair=trade.pair, trade=trade,
current_time=current_time,
current_rate=(bound or current_rate),
current_profit=bound_profit,
after_fill=after_fill)
# Sanity check - error cases will return None
if stop_loss_value:
if stop_loss_value_custom:
stop_loss_value = stop_loss_value_custom
trade.adjust_stop_loss(bound or current_rate, stop_loss_value,
allow_refresh=after_fill)
else: