Extract ft_stoploss_adjust to seperate method

This commit is contained in:
Matthias 2023-02-13 19:53:04 +01:00
parent a0e2f98086
commit ce7d24f529

View File

@ -1153,13 +1153,12 @@ class IStrategy(ABC, HyperStrategyMixin):
return exits return exits
def stop_loss_reached(self, current_rate: float, trade: Trade, def ft_stoploss_adjust(self, current_rate: float, trade: Trade,
current_time: datetime, current_profit: float, current_time: datetime, current_profit: float,
force_stoploss: float, low: Optional[float] = None, force_stoploss: float, low: Optional[float] = None,
high: Optional[float] = None) -> ExitCheckTuple: high: Optional[float] = None) -> None:
""" """
Based on current profit of the trade and configured (trailing) stoploss, Adjust stop-loss dynamically if configured to do so.
decides to exit or not
:param current_profit: current profit as ratio :param current_profit: current profit as ratio
:param low: Low value of this candle, only set in backtesting :param low: Low value of this candle, only set in backtesting
:param high: High value of this candle, only set in backtesting :param high: High value of this candle, only set in backtesting
@ -1205,6 +1204,20 @@ class IStrategy(ABC, HyperStrategyMixin):
trade.adjust_stop_loss(bound or current_rate, stop_loss_value) trade.adjust_stop_loss(bound or current_rate, stop_loss_value)
def stop_loss_reached(self, current_rate: float, trade: Trade,
current_time: datetime, current_profit: float,
force_stoploss: float, low: Optional[float] = None,
high: Optional[float] = None) -> ExitCheckTuple:
"""
Based on current profit of the trade and configured (trailing) stoploss,
decides to exit or not
:param current_profit: current profit as ratio
:param low: Low value of this candle, only set in backtesting
:param high: High value of this candle, only set in backtesting
"""
self.ft_stoploss_adjust(current_rate, trade, current_time, current_profit,
force_stoploss, low, high)
sl_higher_long = (trade.stop_loss >= (low or current_rate) and not trade.is_short) sl_higher_long = (trade.stop_loss >= (low or current_rate) and not trade.is_short)
sl_lower_short = (trade.stop_loss <= (high or current_rate) and trade.is_short) sl_lower_short = (trade.stop_loss <= (high or current_rate) and trade.is_short)
liq_higher_long = (trade.liquidation_price liq_higher_long = (trade.liquidation_price