From 57909749f8b9da776cc0bc1c1e6d36f4ac10414c Mon Sep 17 00:00:00 2001 From: Masoud Azizi Date: Sat, 21 Aug 2021 02:12:58 +0000 Subject: [PATCH 1/2] negative Shift removed, forloop removed to speedup hyperoptio --- user_data/strategies/Diamond.py | 105 +++++++++++--------------------- 1 file changed, 35 insertions(+), 70 deletions(-) diff --git a/user_data/strategies/Diamond.py b/user_data/strategies/Diamond.py index 42e50e4..86d8732 100644 --- a/user_data/strategies/Diamond.py +++ b/user_data/strategies/Diamond.py @@ -10,17 +10,11 @@ # 𝒲𝒽𝑒𝓇𝑒 π’½π’Άπ“ˆ π’½π“Šπ“‚π’Άπ“ƒπ’Ύπ“‰π“Ž π‘”π‘œπ“ƒπ‘’? # π’²π’½π“Ž π“ƒπ‘œπ“‰ 𝒽𝑒𝓁𝓅 π“Œπ’½π‘’π“ƒ π“Œπ‘’ 𝒸𝒢𝓃? # IMPORTANT: This strategy -# designed for "ZERO" loss and "UNDER" -# 15 minuts avg duration.So if you have more -# loss and more avg, Its "NOT" normal result, and -# you will change config.json variables and hyperoption commands -# Thanks To @xmatthias if he was approve the last version of This strategy -# That just a lazy code. I never can reach to this strategy(Now its really a diamond.) -# * freqtrade hyperopt --hyperopt-loss ShortTradeDurHyperOptLoss --spaces all --strategy Diamond -e 700 -j 2 --timerange 20210810-20210813 +# thanks to: @Kroissan, @drakes00 And @xmatthias for his patience and helps +# * freqtrade hyperopt --hyperopt-loss ShortTradeDurHyperOptLoss --spaces buy sell roi trailing --strategy Diamond -e 700 -j 2 # * freqtrade backtesting --strategy Diamond # Author: @Mablue (Masoud Azizi) # github: https://github.com/mablue/ -# (First Hyperopt it.A hyperopt file is available) # --- Do not remove these libs --- from freqtrade.strategy.hyper import CategoricalParameter, DecimalParameter, IntParameter from freqtrade.strategy.interface import IStrategy @@ -32,82 +26,65 @@ import talib.abstract as ta from functools import reduce import freqtrade.vendor.qtpylib.indicators as qtpylib -##### SETINGS ##### -# It hyperopt just one set of params for all buy and sell strategies if true. -DUALFIT = False -COUNT = 10 -GAP = 3 -### END SETINGS ### - class Diamond(IStrategy): # ###################### RESULT PLACE ###################### - # * 6/700: 1 trades. 1/0/0 Wins/Draws/Losses. Avg profit 17.68%. Median profit 17.68%. Total profit 58.94100000 USDT ( 5.89Ξ£%). Avg duration 0:00:00 min. Objective: 1.79949 - + # 1/700: 20 trades. 13/4/3 Wins/Draws/Losses. Avg profit 6.30%. Median profit 7.19%. Total profit 0.04159258 BTC ( 41.59%). Avg duration 2 days, 22:24:00 min. Objective: 1.83361 # Buy hyperspace params: buy_params = { - "buy_fast": 31, - "buy_push": 0.72, - "buy_shift": -7, - "buy_slow": 2, + "buy_fast": 22, + "buy_push": 1.65, + "buy_slow": 16, } # Sell hyperspace params: sell_params = { - "sell_fast": 17, - "sell_push": 1.493, - "sell_shift": -7, - "sell_slow": 28, + "sell_fast": 10, + "sell_push": 1.53, + "sell_slow": 50, } # ROI table: minimal_roi = { - "0": 0.177, - "31": 0.059, - "61": 0.021, - "170": 0 + "0": 0.647, + "992": 0.285, + "2659": 0.072, + "7323": 0 } # Stoploss: - stoploss = -0.241 - + stoploss = -0.259 # Trailing stop: trailing_stop = True - trailing_stop_positive = 0.13 - trailing_stop_positive_offset = 0.189 + trailing_stop_positive = 0.222 + trailing_stop_positive_offset = 0.284 trailing_only_offset_is_reached = True + # Buy hypers - timeframe = '5m' + timeframe = '4h' # #################### END OF RESULT PLACE #################### - buy_push = DecimalParameter(0, 2, decimals=3, default=1, space='buy') - buy_shift = IntParameter(-10, 0, default=-6, space='buy') - buy_fast = IntParameter(2, 50, default=9, space='buy') - buy_slow = IntParameter(2, 50, default=18, space='buy') - if not DUALFIT: - sell_push = DecimalParameter( - 0, 2, decimals=3, default=1, space='sell') - sell_shift = IntParameter(-10, 0, default=-6, space='sell') - sell_fast = IntParameter(2, 50, default=9, space='sell') - sell_slow = IntParameter(2, 50, default=18, space='sell') + buy_push = DecimalParameter(1, 2, decimals=2, default=1, space='buy') + sell_push = DecimalParameter(1, 2, decimals=2, default=1, space='sell') + buy_fast = IntParameter(2, 30, default=1, space='buy') + buy_slow = IntParameter(2, 50, default=1, space='buy') + sell_fast = IntParameter(2, 30, default=1, space='sell') + sell_slow = IntParameter(2, 50, default=1, space='sell') def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: return dataframe def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: - dataframe['buy_ema_fast'] = ta.SMA( + dataframe['buy_ma_fast'] = ta.SMA( dataframe, timeperiod=int(self.buy_fast.value)) - dataframe['buy_ema_slow'] = ta.SMA( + dataframe['buy_ma_slow'] = ta.SMA( dataframe, timeperiod=int(self.buy_slow.value)) conditions = [] - conditions.append( - qtpylib.crossed_above( - dataframe['buy_ema_fast'].shift(self.buy_shift.value), - dataframe['buy_ema_slow'].shift( - self.buy_shift.value)*self.buy_push.value - ) + (dataframe['buy_ma_fast']/dataframe['buy_ma_slow'] + ).between(1, self.buy_push.value) + ) if conditions: @@ -118,28 +95,16 @@ class Diamond(IStrategy): return dataframe def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: - push = self.buy_push.value - shift = self.buy_shift.value - ema_fast = dataframe['buy_ema_fast'] - ema_slow = dataframe['buy_ema_slow'] - - if not DUALFIT: - push = self.sell_push.value - shift = self.sell_shift.value - ema_fast = dataframe['sell_ema_fast'] = ta.SMA( - dataframe, timeperiod=int(self.buy_fast.value)) - ema_slow = dataframe['sell_ema_slow'] = ta.SMA( - dataframe, timeperiod=int(self.buy_slow.value)) + dataframe['sell_ma_fast'] = ta.SMA( + dataframe, timeperiod=int(self.sell_fast.value)) + dataframe['sell_ma_slow'] = ta.SMA( + dataframe, timeperiod=int(self.sell_slow.value)) conditions = [] - conditions.append( - qtpylib.crossed_below( - ema_fast.shift(shift), - ema_slow.shift(shift)*push - ) + (dataframe['sell_ma_slow']/dataframe['sell_ma_fast'] + ).between(1, self.sell_push.value) ) - if conditions: dataframe.loc[ reduce(lambda x, y: x & y, conditions), From e7fcca2aa458eae6c87112cc537aaa96c3616446 Mon Sep 17 00:00:00 2001 From: Masoud Azizi Date: Sat, 21 Aug 2021 22:12:17 +0000 Subject: [PATCH 2/2] Diamond shift added also tested and works well in live ;) --- user_data/strategies/Diamond.py | 129 +++++++++++++++++++++----------- 1 file changed, 86 insertions(+), 43 deletions(-) diff --git a/user_data/strategies/Diamond.py b/user_data/strategies/Diamond.py index 86d8732..d69e79e 100644 --- a/user_data/strategies/Diamond.py +++ b/user_data/strategies/Diamond.py @@ -9,12 +9,36 @@ # 𝒲𝒽𝑒𝓇𝑒 π’½π’Άπ“ˆ π‘œπ“Šπ“‡ π’½π“Šπ“‚π’Άπ“ƒπ’Ύπ“‰π“Ž π‘”π‘œπ“ƒπ‘’? # 𝒲𝒽𝑒𝓇𝑒 π’½π’Άπ“ˆ π’½π“Šπ“‚π’Άπ“ƒπ’Ύπ“‰π“Ž π‘”π‘œπ“ƒπ‘’? # π’²π’½π“Ž π“ƒπ‘œπ“‰ 𝒽𝑒𝓁𝓅 π“Œπ’½π‘’π“ƒ π“Œπ‘’ 𝒸𝒢𝓃? -# IMPORTANT: This strategy +# π“π‘’π“‰π“ˆ 𝓅𝒾𝓅 π“Šπ“ƒπ’Ύπ“ƒπ“ˆπ“‰π’Άπ“π“ 𝓉𝒢-𝓁𝒾𝒷 π‘œπ“ƒ π’œπ’»π‘”π’½π’Άπ“ƒπ’Ύπ“ˆπ“‰π’Άπ“ƒ + +# IMPORTANT: Diamond strategy is designed to be pure and +# cuz of that it have not any indicator population. idea is that +# It is just use the pure dataframe ohlcv data for calculation +# of buy/sell signals, But you can add your indicators and add +# your key names inside catagorical hyperoptable params and +# than you be able to hyperopt them as well. # thanks to: @Kroissan, @drakes00 And @xmatthias for his patience and helps -# * freqtrade hyperopt --hyperopt-loss ShortTradeDurHyperOptLoss --spaces buy sell roi trailing --strategy Diamond -e 700 -j 2 -# * freqtrade backtesting --strategy Diamond # Author: @Mablue (Masoud Azizi) # github: https://github.com/mablue/ +# * freqtrade backtesting --strategy Diamond + +# freqtrade hyperopt --hyperopt-loss ShortTradeDurHyperOptLoss --spaces buy sell roi trailing stoploss --strategy Diamond -j 2 -e 10 +# * 3/10: 76 trades. 51/18/7 Wins/Draws/Losses. Avg profit 1.92%. Median profit 2.40%. Total profit 0.04808472 BTC ( 48.08%). Avg duration 5:06:00 min. Objective: 1.75299 +# freqtrade hyperopt --hyperopt-loss OnlyProfitHyperOptLoss --spaces buy sell roi trailing stoploss --strategy Diamond -j 2 -e 10 +# * 10/10: 76 trades. 39/34/3 Wins/Draws/Losses. Avg profit 0.61%. Median profit 0.05%. Total profit 0.01528359 BTC ( 15.28%). Avg duration 17:32:00 min. Objective: -0.01528 +# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --spaces buy sell roi trailing stoploss --strategy Diamond -j 2 -e 10 +# * 4/10: 15 trades. 10/2/3 Wins/Draws/Losses. Avg profit 1.52%. Median profit 7.99%. Total profit 0.00754274 BTC ( 7.54%). Avg duration 1 day, 0:04:00 min. Objective: -0.90653 +# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces buy sell roi trailing stoploss --strategy Diamond -j 2 -e 10 +# * 7/10: 130 trades. 68/54/8 Wins/Draws/Losses. Avg profit 0.71%. Median profit 0.06%. Total profit 0.03050369 BTC ( 30.50%). Avg duration 10:07:00 min. Objective: -11.08185 +# freqtrade hyperopt --hyperopt-loss SortinoHyperOptLoss --spaces buy sell roi trailing stoploss --strategy Diamond -j 2 -e 10 +# * 2/10: 10 trades. 7/0/3 Wins/Draws/Losses. Avg profit 5.50%. Median profit 7.05%. Total profit 0.01817970 BTC ( 18.18%). Avg duration 0:27:00 min. Objective: -11.72450 +# freqtrade hyperopt --hyperopt-loss SortinoHyperOptLossDaily --spaces buy sell roi trailing stoploss --strategy Diamond -j 2 -e 10 +# | * Best | 3/10 | 165 | 98 63 4 | 1.00% | 0.05453885 BTC (54.54%) | 0 days 08:02:00 | 0.00442974 BTC (13.41%) | -41.371 | +# | * Best | 7/10 | 101 | 56 42 3 | 0.73% | 0.02444518 BTC (24.45%) | 0 days 13:08:00 | 0.00107122 BTC (3.24%) | -66.7687 | +# * 7/10: 101 trades. 56/42/3 Wins/Draws/Losses. Avg profit 0.73%. Median profit 0.13%. Total profit 0.02444518 BTC ( 24.45%). Avg duration 13:08:00 min. Objective: -66.76866 +# freqtrade hyperopt --hyperopt-loss OnlyProfitHyperOptLoss --spaces buy sell roi trailing stoploss --strategy Diamond -j 2 -e 10 +# * 7/10: 117 trades. 74/41/2 Wins/Draws/Losses. Avg profit 1.91%. Median profit 1.50%. Total profit 0.07370921 BTC ( 73.71%). Avg duration 9:26:00 min. Objective: -0.07371 + # --- Do not remove these libs --- from freqtrade.strategy.hyper import CategoricalParameter, DecimalParameter, IntParameter from freqtrade.strategy.interface import IStrategy @@ -29,62 +53,83 @@ import freqtrade.vendor.qtpylib.indicators as qtpylib class Diamond(IStrategy): # ###################### RESULT PLACE ###################### - # 1/700: 20 trades. 13/4/3 Wins/Draws/Losses. Avg profit 6.30%. Median profit 7.19%. Total profit 0.04159258 BTC ( 41.59%). Avg duration 2 days, 22:24:00 min. Objective: 1.83361 + # Config: 5 x UNLIMITED STOCK costume pair list, + # hyperopt : 5000 x SortinoHyperOptLossDaily, + # 34/5000: 297 trades. 136/156/5 Wins/Draws/Losses. Avg profit 0.49%. Median profit 0.00%. Total profit 45.84477237 USDT ( 33.96Ξ£%). Avg duration 11:54:00 min. Objective: -46.50379 + # Buy hyperspace params: buy_params = { - "buy_fast": 22, - "buy_push": 1.65, - "buy_slow": 16, + "buy_fast_key": "high", + "buy_horizontal_push": 7, + "buy_slow_key": "volume", + "buy_vertical_push": 0.942, } # Sell hyperspace params: sell_params = { - "sell_fast": 10, - "sell_push": 1.53, - "sell_slow": 50, + "sell_fast_key": "high", + "sell_horizontal_push": 10, + "sell_slow_key": "low", + "sell_vertical_push": 1.184, } # ROI table: minimal_roi = { - "0": 0.647, - "992": 0.285, - "2659": 0.072, - "7323": 0 + "0": 0.242, + "13": 0.044, + "51": 0.02, + "170": 0 } # Stoploss: - stoploss = -0.259 + stoploss = -0.271 + # Trailing stop: trailing_stop = True - trailing_stop_positive = 0.222 - trailing_stop_positive_offset = 0.284 - trailing_only_offset_is_reached = True - - # Buy hypers - timeframe = '4h' + trailing_stop_positive = 0.011 + trailing_stop_positive_offset = 0.054 + trailing_only_offset_is_reached = False + # timeframe + timeframe = '5m' # #################### END OF RESULT PLACE #################### - buy_push = DecimalParameter(1, 2, decimals=2, default=1, space='buy') - sell_push = DecimalParameter(1, 2, decimals=2, default=1, space='sell') - buy_fast = IntParameter(2, 30, default=1, space='buy') - buy_slow = IntParameter(2, 50, default=1, space='buy') - sell_fast = IntParameter(2, 30, default=1, space='sell') - sell_slow = IntParameter(2, 50, default=1, space='sell') + + buy_vertical_push = DecimalParameter(0.5, 1.5, decimals=3, default=1, space='buy') + buy_horizontal_push = IntParameter(0, 10, default=0, space='buy') + buy_fast_key = CategoricalParameter(['open', 'high', 'low', 'close', 'volume', + # you can not enable this lines befour you + # populate an indicator for them and set + # the same key name for it + # 'ma_fast', 'ma_slow', {...} + ], default='ma_fast', space='buy') + buy_slow_key = CategoricalParameter(['open', 'high', 'low', 'close', 'volume', + # 'ma_fast', 'ma_slow', {...} + ], default='ma_slow', space='buy') + + sell_vertical_push = DecimalParameter(0.5, 1.5, decimals=3, default=1, space='sell') + sell_horizontal_push = IntParameter(0, 10, default=0, space='sell') + sell_fast_key = CategoricalParameter(['open', 'high', 'low', 'close', 'volume', + # 'ma_fast', 'ma_slow', {...} + ], default='ma_fast', space='sell') + sell_slow_key = CategoricalParameter(['open', 'high', 'low', 'close', 'volume', + # 'ma_fast', 'ma_slow', {...} + ], default='ma_slow', space='sell') def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: - + # you can add new indicators and enable them inside + # hyperoptable categorical params on the top + # dataframe['ma_fast'] = ta.SMA(dataframe, timeperiod=9) + # dataframe['ma_slow'] = ta.SMA(dataframe, timeperiod=18) + # dataframe['{...}'] = ta.{...}(dataframe, timeperiod={...}) return dataframe def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: - dataframe['buy_ma_fast'] = ta.SMA( - dataframe, timeperiod=int(self.buy_fast.value)) - dataframe['buy_ma_slow'] = ta.SMA( - dataframe, timeperiod=int(self.buy_slow.value)) - conditions = [] conditions.append( - (dataframe['buy_ma_fast']/dataframe['buy_ma_slow'] - ).between(1, self.buy_push.value) - + qtpylib.crossed_above + ( + dataframe[self.buy_fast_key.value].shift(self.buy_horizontal_push.value), + dataframe[self.buy_slow_key.value] * self.buy_vertical_push.value + ) ) if conditions: @@ -95,15 +140,13 @@ class Diamond(IStrategy): return dataframe def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: - dataframe['sell_ma_fast'] = ta.SMA( - dataframe, timeperiod=int(self.sell_fast.value)) - dataframe['sell_ma_slow'] = ta.SMA( - dataframe, timeperiod=int(self.sell_slow.value)) - conditions = [] conditions.append( - (dataframe['sell_ma_slow']/dataframe['sell_ma_fast'] - ).between(1, self.sell_push.value) + qtpylib.crossed_below + ( + dataframe[self.sell_fast_key.value].shift(self.sell_horizontal_push.value), + dataframe[self.sell_slow_key.value] * self.sell_vertical_push.value + ) ) if conditions: dataframe.loc[