Use crossed() in sample strategy

This commit is contained in:
Matthias 2019-10-14 20:13:34 +02:00
parent 96bd5a6dc1
commit 790e6146f5
2 changed files with 16 additions and 11 deletions

View File

@ -138,15 +138,19 @@ def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
""" """
dataframe.loc[ dataframe.loc[
( (
(dataframe['adx'] > 30) & (qtpylib.crossed_above(dataframe['adx'], 30)) & # Signal: ADX crosses baove 30
(dataframe['tema'] <= dataframe['bb_middleband']) & (dataframe['tema'] <= dataframe['bb_middleband']) & # Guard
(dataframe['tema'] > dataframe['tema'].shift(1)) (dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard
(dataframe['volume'] > 0) # Make sure Volume is not 0
), ),
'buy'] = 1 'buy'] = 1
return dataframe return dataframe
``` ```
!!! Note
Buying requires sellers to buy from - therefore volume needs to be > 0 (`dataframe['volume'] > 0`) to make sure backtesting does not buy/sell in no-activity periods.
### Sell signal rules ### Sell signal rules
Edit the method `populate_sell_trend()` into your strategy file to update your sell strategy. Edit the method `populate_sell_trend()` into your strategy file to update your sell strategy.
@ -168,9 +172,10 @@ def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame
""" """
dataframe.loc[ dataframe.loc[
( (
(dataframe['adx'] > 70) & (qtpylib.crossed_above(dataframe['adx'], 70)) & # Signal: ADX crosses above 30
(dataframe['tema'] > dataframe['bb_middleband']) & (dataframe['tema'] > dataframe['bb_middleband']) & # Guard
(dataframe['tema'] < dataframe['tema'].shift(1)) (dataframe['tema'] < dataframe['tema'].shift(1)) & #Guard
(dataframe['volume'] > 0) # Make sure Volume is not 0
), ),
'sell'] = 1 'sell'] = 1
return dataframe return dataframe

View File

@ -277,9 +277,9 @@ class SampleStrategy(IStrategy):
""" """
dataframe.loc[ dataframe.loc[
( (
(dataframe['adx'] > 30) & (qtpylib.crossed_above(dataframe['adx'], 30)) & # Signal: ADX crosses above 30
(dataframe['tema'] <= dataframe['bb_middleband']) & (dataframe['tema'] <= dataframe['bb_middleband']) & # Guard: tema below BB middle
(dataframe['tema'] > dataframe['tema'].shift(1)) & (dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard: tema is raising
(dataframe['volume'] > 0) # Make sure Volume is not 0 (dataframe['volume'] > 0) # Make sure Volume is not 0
), ),
'buy'] = 1 'buy'] = 1
@ -295,9 +295,9 @@ class SampleStrategy(IStrategy):
""" """
dataframe.loc[ dataframe.loc[
( (
(dataframe['adx'] > 70) & (qtpylib.crossed_above(dataframe['adx'], 70)) & # Signal: - ADX crosses above 70
(dataframe['tema'] > dataframe['bb_middleband']) & (dataframe['tema'] > dataframe['bb_middleband']) &
(dataframe['tema'] < dataframe['tema'].shift(1)) & (dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard: tema is raising
(dataframe['volume'] > 0) # Make sure Volume is not 0 (dataframe['volume'] > 0) # Make sure Volume is not 0
), ),
'sell'] = 1 'sell'] = 1