Improve handling of None values from custom_stoploss
This commit is contained in:
@@ -578,10 +578,10 @@ class Backtesting:
|
|||||||
""" Rate is within candle, therefore filled"""
|
""" Rate is within candle, therefore filled"""
|
||||||
return row[LOW_IDX] <= rate <= row[HIGH_IDX]
|
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)
|
profit = trade.calc_profit_ratio(current_rate)
|
||||||
self.strategy.ft_stoploss_adjust(current_rate, trade, current_date, profit, 0,
|
self.strategy.ft_stoploss_adjust(current_rate, trade, # type: ignore
|
||||||
after_fill=True)
|
current_date, profit, 0, after_fill=True)
|
||||||
|
|
||||||
def _try_close_open_order(
|
def _try_close_open_order(
|
||||||
self, order: Optional[Order], trade: LocalTrade, current_date: datetime,
|
self, order: Optional[Order], trade: LocalTrade, current_date: datetime,
|
||||||
|
|||||||
@@ -1188,15 +1188,16 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
bound = (low if trade.is_short else high)
|
bound = (low if trade.is_short else high)
|
||||||
bound_profit = current_profit if not bound else trade.calc_profit_ratio(bound)
|
bound_profit = current_profit if not bound else trade.calc_profit_ratio(bound)
|
||||||
if self.use_custom_stoploss and dir_correct:
|
if self.use_custom_stoploss and dir_correct:
|
||||||
stop_loss_value = strategy_safe_wrapper(self.custom_stoploss, default_retval=None,
|
stop_loss_value_custom = strategy_safe_wrapper(
|
||||||
supress_error=True
|
self.custom_stoploss, default_retval=None, supress_error=True
|
||||||
)(pair=trade.pair, trade=trade,
|
)(pair=trade.pair, trade=trade,
|
||||||
current_time=current_time,
|
current_time=current_time,
|
||||||
current_rate=(bound or current_rate),
|
current_rate=(bound or current_rate),
|
||||||
current_profit=bound_profit,
|
current_profit=bound_profit,
|
||||||
after_fill=after_fill)
|
after_fill=after_fill)
|
||||||
# Sanity check - error cases will return None
|
# 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,
|
trade.adjust_stop_loss(bound or current_rate, stop_loss_value,
|
||||||
allow_refresh=after_fill)
|
allow_refresh=after_fill)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user