Add very simple short logic to test-strategy

This commit is contained in:
Matthias 2021-09-22 20:36:03 +02:00
parent 5928ba9c88
commit 4c6b1cd55b
2 changed files with 18 additions and 3 deletions

View File

@ -139,6 +139,10 @@ class Backtesting:
self.config['startup_candle_count'] = self.required_startup self.config['startup_candle_count'] = self.required_startup
self.exchange.validate_required_startup_candles(self.required_startup, self.timeframe) 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.progress = BTProgress()
self.abort = False self.abort = False
@ -499,8 +503,8 @@ class Backtesting:
def check_for_trade_entry(self, row) -> Optional[str]: def check_for_trade_entry(self, row) -> Optional[str]:
enter_long = row[LONG_IDX] == 1 enter_long = row[LONG_IDX] == 1
exit_long = row[ELONG_IDX] == 1 exit_long = row[ELONG_IDX] == 1
enter_short = row[SHORT_IDX] == 1 enter_short = self._can_short and row[SHORT_IDX] == 1
exit_short = row[ESHORT_IDX] == 1 exit_short = self._can_short and row[ESHORT_IDX] == 1
if enter_long == 1 and not any([exit_long, enter_short]): if enter_long == 1 and not any([exit_long, enter_short]):
# Long # Long

View File

@ -1,6 +1,7 @@
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement # pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
from datetime import datetime from datetime import datetime
import talib.abstract as ta import talib.abstract as ta
from pandas import DataFrame from pandas import DataFrame
@ -138,7 +139,11 @@ class StrategyTestV3(IStrategy):
(dataframe['plus_di'] > self.buy_plusdi.value) (dataframe['plus_di'] > self.buy_plusdi.value)
), ),
'enter_long'] = 1 'enter_long'] = 1
# TODO-lev: Add short logic dataframe.loc[
(
qtpylib.crossed_below(dataframe['rsi'], self.sell_rsi.value)
),
'enter_short'] = 1
return dataframe return dataframe
@ -158,6 +163,12 @@ class StrategyTestV3(IStrategy):
), ),
'exit_long'] = 1 'exit_long'] = 1
dataframe.loc[
(
qtpylib.crossed_above(dataframe['rsi'], self.buy_rsi.value)
),
'exit_short'] = 1
# TODO-lev: Add short logic # TODO-lev: Add short logic
return dataframe return dataframe