diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index b43222fb3..429ba7251 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -139,6 +139,10 @@ class Backtesting: self.config['startup_candle_count'] = self.required_startup self.exchange.validate_required_startup_candles(self.required_startup, self.timeframe) + # TODO-lev: This should come from the configuration setting or better a + # TODO-lev: combination of config/strategy "use_shorts"(?) and "can_short" from the exchange + self._can_short = False + self.progress = BTProgress() self.abort = False @@ -499,8 +503,8 @@ class Backtesting: def check_for_trade_entry(self, row) -> Optional[str]: enter_long = row[LONG_IDX] == 1 exit_long = row[ELONG_IDX] == 1 - enter_short = row[SHORT_IDX] == 1 - exit_short = row[ESHORT_IDX] == 1 + enter_short = self._can_short and row[SHORT_IDX] == 1 + exit_short = self._can_short and row[ESHORT_IDX] == 1 if enter_long == 1 and not any([exit_long, enter_short]): # Long diff --git a/tests/strategy/strats/strategy_test_v3.py b/tests/strategy/strats/strategy_test_v3.py index 18c4ec93f..115211a7c 100644 --- a/tests/strategy/strats/strategy_test_v3.py +++ b/tests/strategy/strats/strategy_test_v3.py @@ -1,6 +1,7 @@ # pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement from datetime import datetime + import talib.abstract as ta from pandas import DataFrame @@ -138,7 +139,11 @@ class StrategyTestV3(IStrategy): (dataframe['plus_di'] > self.buy_plusdi.value) ), 'enter_long'] = 1 - # TODO-lev: Add short logic + dataframe.loc[ + ( + qtpylib.crossed_below(dataframe['rsi'], self.sell_rsi.value) + ), + 'enter_short'] = 1 return dataframe @@ -158,6 +163,12 @@ class StrategyTestV3(IStrategy): ), 'exit_long'] = 1 + dataframe.loc[ + ( + qtpylib.crossed_above(dataframe['rsi'], self.buy_rsi.value) + ), + 'exit_short'] = 1 + # TODO-lev: Add short logic return dataframe