From 790e6146f504f6a3f1ae35a0630701ae4afe81b2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 14 Oct 2019 20:13:34 +0200 Subject: [PATCH] Use crossed() in sample strategy --- docs/strategy-customization.md | 17 +++++++++++------ user_data/strategies/sample_strategy.py | 10 +++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/strategy-customization.md b/docs/strategy-customization.md index adcdf0208..39a36c469 100644 --- a/docs/strategy-customization.md +++ b/docs/strategy-customization.md @@ -138,15 +138,19 @@ def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ dataframe.loc[ ( - (dataframe['adx'] > 30) & - (dataframe['tema'] <= dataframe['bb_middleband']) & - (dataframe['tema'] > dataframe['tema'].shift(1)) + (qtpylib.crossed_above(dataframe['adx'], 30)) & # Signal: ADX crosses baove 30 + (dataframe['tema'] <= dataframe['bb_middleband']) & # Guard + (dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard + (dataframe['volume'] > 0) # Make sure Volume is not 0 ), 'buy'] = 1 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 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['adx'] > 70) & - (dataframe['tema'] > dataframe['bb_middleband']) & - (dataframe['tema'] < dataframe['tema'].shift(1)) + (qtpylib.crossed_above(dataframe['adx'], 70)) & # Signal: ADX crosses above 30 + (dataframe['tema'] > dataframe['bb_middleband']) & # Guard + (dataframe['tema'] < dataframe['tema'].shift(1)) & #Guard + (dataframe['volume'] > 0) # Make sure Volume is not 0 ), 'sell'] = 1 return dataframe diff --git a/user_data/strategies/sample_strategy.py b/user_data/strategies/sample_strategy.py index 623addb1e..84ff9ec2c 100644 --- a/user_data/strategies/sample_strategy.py +++ b/user_data/strategies/sample_strategy.py @@ -277,9 +277,9 @@ class SampleStrategy(IStrategy): """ dataframe.loc[ ( - (dataframe['adx'] > 30) & - (dataframe['tema'] <= dataframe['bb_middleband']) & - (dataframe['tema'] > dataframe['tema'].shift(1)) & + (qtpylib.crossed_above(dataframe['adx'], 30)) & # Signal: ADX crosses above 30 + (dataframe['tema'] <= dataframe['bb_middleband']) & # Guard: tema below BB middle + (dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard: tema is raising (dataframe['volume'] > 0) # Make sure Volume is not 0 ), 'buy'] = 1 @@ -295,9 +295,9 @@ class SampleStrategy(IStrategy): """ dataframe.loc[ ( - (dataframe['adx'] > 70) & + (qtpylib.crossed_above(dataframe['adx'], 70)) & # Signal: - ADX crosses above 70 (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 ), 'sell'] = 1