From cb5a0f394e882aad5077ea3aa94ab0f472b42124 Mon Sep 17 00:00:00 2001 From: Pedro Povoleri Date: Sat, 7 Jan 2023 21:52:13 +0100 Subject: [PATCH 1/3] add TrendFollowingStrategy --- .../futures/TrendFollowingStrategy.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 user_data/strategies/futures/TrendFollowingStrategy.py diff --git a/user_data/strategies/futures/TrendFollowingStrategy.py b/user_data/strategies/futures/TrendFollowingStrategy.py new file mode 100644 index 0000000..03217ba --- /dev/null +++ b/user_data/strategies/futures/TrendFollowingStrategy.py @@ -0,0 +1,52 @@ +from functools import reduce +from pandas import DataFrame +from freqtrade.strategy import IStrategy + +import talib.abstract as ta + +from freqtrade.strategy.interface import IStrategy + +class TrendFollowingStrategy(IStrategy): + def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + # Calculate OBV + dataframe['obv'] = ta.OBV(dataframe['close'], dataframe['volume']) + + # Add your trend following indicators here + dataframe['trend'] = dataframe['close'].ewm(span=20, adjust=False).mean() + + return dataframe + + def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + # Add your trend following buy signals here + dataframe.loc[ + (dataframe['close'] > dataframe['trend']) & + (dataframe['close'].shift(1) <= dataframe['trend'].shift(1)) & + (dataframe['obv'] > dataframe['obv'].shift(1)), + 'enter_long'] = 1 + + # Add your trend following sell signals here + dataframe.loc[ + (dataframe['close'] < dataframe['trend']) & + (dataframe['close'].shift(1) >= dataframe['trend'].shift(1)) & + (dataframe['obv'] < dataframe['obv'].shift(1)), + 'enter_short'] = -1 + + return dataframe + + def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + # Add your trend following exit signals for long positions here + dataframe.loc[ + (dataframe['close'] < dataframe['trend']) & + (dataframe['close'].shift(1) >= dataframe['trend'].shift(1)) & + (dataframe['obv'] > dataframe['obv'].shift(1)), + 'exit_long'] = 1 + + # Add your trend following exit signals for short positions here + dataframe.loc[ + (dataframe['close'] > dataframe['trend']) & + (dataframe['close'].shift(1) <= dataframe['trend'].shift(1)) & + (dataframe['obv'] < dataframe['obv'].shift(1)), + 'exit_short'] = 1 + + return dataframe + From f8e5ecc4032fe80a3c18b3a211fbefdd0085bd82 Mon Sep 17 00:00:00 2001 From: Pedro Povoleri Date: Sun, 8 Jan 2023 11:06:17 +0100 Subject: [PATCH 2/3] Attend PR comment. --- .../strategies/futures/VolatilitySystem.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 user_data/strategies/futures/VolatilitySystem.py diff --git a/user_data/strategies/futures/VolatilitySystem.py b/user_data/strategies/futures/VolatilitySystem.py new file mode 100644 index 0000000..734cc60 --- /dev/null +++ b/user_data/strategies/futures/VolatilitySystem.py @@ -0,0 +1,57 @@ +from freqtrade.strategy.interface import IStrategy +from pandas import DataFrame +import talib.abstract as ta + +class VolatilitySystem(IStrategy): + + INTERFACE_VERSION: int = 3 + # ROI table: + minimal_roi = {"0": 0.15, "30": 0.1, "60": 0.05} + # minimal_roi = {"0": 1} + + # Stoploss: + stoploss = -0.265 + + # Trailing stop: + trailing_stop = True + trailing_stop_positive = 0.05 + trailing_stop_positive_offset = 0.1 + trailing_only_offset_is_reached = False + + timeframe = "5m" + + def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + # Calculate ATR + dataframe['atr'] = ta.ATR(dataframe, timeperiod=14) * 2.0 + dataframe['close_change'] = dataframe['close'].pct_change() + return dataframe + + def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + # Add long entry signals + dataframe.loc[ + (dataframe['close_change'] > dataframe['atr']) & + (dataframe['close'].shift(1) <= dataframe['atr'].shift(1)), + 'enter_long'] = 1 + + # Add short entry signals + dataframe.loc[ + (dataframe['close_change'] < -dataframe['atr']) & + (dataframe['close'].shift(1) >= -dataframe['atr'].shift(1)), + 'enter_short'] = 1 + + return dataframe + + def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + # Add long exit signals + dataframe.loc[ + (dataframe['close_change'] < dataframe['atr']) & + (dataframe['close'].shift(1) >= dataframe['atr'].shift(1)), + 'exit_long'] = 1 + + # Add short exit signals + dataframe.loc[ + (dataframe['close_change'] > -dataframe['atr']) & + (dataframe['close'].shift(1) <= -dataframe['atr'].shift(1)), + 'exit_short'] = 1 + + return dataframe From a197613a7ada99cd608dbf2f16c834cefe6a114c Mon Sep 17 00:00:00 2001 From: Pedro Povoleri Date: Sun, 8 Jan 2023 12:38:24 +0100 Subject: [PATCH 3/3] Fix PR coments. --- .../futures/TrendFollowingStrategy.py | 17 ++++++ .../strategies/futures/VolatilitySystem.py | 57 ------------------- 2 files changed, 17 insertions(+), 57 deletions(-) delete mode 100644 user_data/strategies/futures/VolatilitySystem.py diff --git a/user_data/strategies/futures/TrendFollowingStrategy.py b/user_data/strategies/futures/TrendFollowingStrategy.py index 03217ba..2d79dd1 100644 --- a/user_data/strategies/futures/TrendFollowingStrategy.py +++ b/user_data/strategies/futures/TrendFollowingStrategy.py @@ -7,6 +7,23 @@ import talib.abstract as ta from freqtrade.strategy.interface import IStrategy class TrendFollowingStrategy(IStrategy): + + INTERFACE_VERSION: int = 3 + # ROI table: + minimal_roi = {"0": 0.15, "30": 0.1, "60": 0.05} + # minimal_roi = {"0": 1} + + # Stoploss: + stoploss = -0.265 + + # Trailing stop: + trailing_stop = True + trailing_stop_positive = 0.05 + trailing_stop_positive_offset = 0.1 + trailing_only_offset_is_reached = False + + timeframe = "5m" + def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Calculate OBV dataframe['obv'] = ta.OBV(dataframe['close'], dataframe['volume']) diff --git a/user_data/strategies/futures/VolatilitySystem.py b/user_data/strategies/futures/VolatilitySystem.py deleted file mode 100644 index 734cc60..0000000 --- a/user_data/strategies/futures/VolatilitySystem.py +++ /dev/null @@ -1,57 +0,0 @@ -from freqtrade.strategy.interface import IStrategy -from pandas import DataFrame -import talib.abstract as ta - -class VolatilitySystem(IStrategy): - - INTERFACE_VERSION: int = 3 - # ROI table: - minimal_roi = {"0": 0.15, "30": 0.1, "60": 0.05} - # minimal_roi = {"0": 1} - - # Stoploss: - stoploss = -0.265 - - # Trailing stop: - trailing_stop = True - trailing_stop_positive = 0.05 - trailing_stop_positive_offset = 0.1 - trailing_only_offset_is_reached = False - - timeframe = "5m" - - def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: - # Calculate ATR - dataframe['atr'] = ta.ATR(dataframe, timeperiod=14) * 2.0 - dataframe['close_change'] = dataframe['close'].pct_change() - return dataframe - - def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: - # Add long entry signals - dataframe.loc[ - (dataframe['close_change'] > dataframe['atr']) & - (dataframe['close'].shift(1) <= dataframe['atr'].shift(1)), - 'enter_long'] = 1 - - # Add short entry signals - dataframe.loc[ - (dataframe['close_change'] < -dataframe['atr']) & - (dataframe['close'].shift(1) >= -dataframe['atr'].shift(1)), - 'enter_short'] = 1 - - return dataframe - - def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: - # Add long exit signals - dataframe.loc[ - (dataframe['close_change'] < dataframe['atr']) & - (dataframe['close'].shift(1) >= dataframe['atr'].shift(1)), - 'exit_long'] = 1 - - # Add short exit signals - dataframe.loc[ - (dataframe['close_change'] > -dataframe['atr']) & - (dataframe['close'].shift(1) <= -dataframe['atr'].shift(1)), - 'exit_short'] = 1 - - return dataframe