From 6524edbb4e17472b6893d9a669cd31825fafa9d8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 24 Aug 2021 20:47:54 +0200 Subject: [PATCH] Simplify should_exit interface --- freqtrade/freqtradebot.py | 2 +- freqtrade/optimize/backtesting.py | 5 +++-- freqtrade/strategy/interface.py | 6 +----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 0ddee5292..7c43b599d 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -858,7 +858,7 @@ class FreqtradeBot(LoggingMixin): Check and execute trade exit """ should_exit: SellCheckTuple = self.strategy.should_exit( - trade, sell_rate, datetime.now(timezone.utc), enter, exit_, + trade, sell_rate, datetime.now(timezone.utc), enter=enter, exit_=exit_, force_stoploss=self.edge.stoploss(trade.pair) if self.edge else 0 ) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index c3cd5b114..3bd7f178c 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -333,10 +333,11 @@ class Backtesting: def _get_sell_trade_entry(self, trade: LocalTrade, sell_row: Tuple) -> Optional[LocalTrade]: sell_candle_time = sell_row[DATE_IDX].to_pydatetime() + enter = sell_row[LONG_IDX] if trade.is_short else sell_row[SHORT_IDX] + exit_ = sell_row[ELONG_IDX] if trade.is_short else sell_row[ESHORT_IDX] sell = self.strategy.should_exit( trade, sell_row[OPEN_IDX], sell_candle_time, # type: ignore - enter_long=sell_row[LONG_IDX], enter_short=sell_row[SHORT_IDX], - exit_long=sell_row[ELONG_IDX], exit_short=sell_row[ESHORT_IDX], + enter=enter, exit_=exit_, low=sell_row[LOW_IDX], high=sell_row[HIGH_IDX] ) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 000e2b2dd..f9919877c 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -666,8 +666,7 @@ class IStrategy(ABC, HyperStrategyMixin): return False def should_exit(self, trade: Trade, rate: float, date: datetime, *, - enter_long: bool, enter_short: bool, - exit_long: bool, exit_short: bool, + enter: bool, exit_: bool, low: float = None, high: float = None, force_stoploss: float = 0) -> SellCheckTuple: """ @@ -679,9 +678,6 @@ class IStrategy(ABC, HyperStrategyMixin): :return: True if trade should be exited, False otherwise """ - enter = enter_short if trade.is_short else enter_long - exit_ = exit_short if trade.is_short else exit_long - current_rate = rate current_profit = trade.calc_profit_ratio(current_rate)