From e76cae7bbb9529eeb6ff0704f3eb507a78638ffb Mon Sep 17 00:00:00 2001 From: girdakan Date: Fri, 5 Nov 2021 20:55:59 +0000 Subject: [PATCH 1/3] Khayyam strategy added --- user_data/strategies/Khayyam.py | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 user_data/strategies/Khayyam.py diff --git a/user_data/strategies/Khayyam.py b/user_data/strategies/Khayyam.py new file mode 100644 index 0000000..05a9885 --- /dev/null +++ b/user_data/strategies/Khayyam.py @@ -0,0 +1,60 @@ +# Khayyam Strategy +# In this strategy we try to find the best hours to buy and sell in a day.(in hourly timeframe) +# Cuz of that you should just use 1h timeframe on this strategy. +# Name of this strategy come from the Omar khayyam who was a Persian polymath, +# mathematician, astronomer, philosopher, and poet! +# https://en.wikipedia.org/wiki/Omar_Khayyam +# Author: @Mablue (Masoud Azizi) +# github: https://github.com/mablue/ +# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --strategy Khayyam + +from freqtrade.strategy.hyper import IntParameter +from freqtrade.strategy import IStrategy +from pandas import DataFrame +# -------------------------------- +# Add your lib to import here + + +class Khayyam(IStrategy): + # ROI table: + minimal_roi = { + "0": 0.434, + "391": 0.116, + "511": 0.025, + "1919": 0 + } + + # Stoploss: + stoploss = -0.29 + + # Optimal timeframe + timeframe = '1h' + + buy_hour_max = IntParameter(0, 24, default=24, space='buy') + buy_hour_min = IntParameter(0, 24, default=11, space='buy') + + sell_hour_max = IntParameter(0, 24, default=6, space='sell') + sell_hour_min = IntParameter(0, 24, default=15, space='sell') + + def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + return dataframe + + def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + dataframe.loc[ + ( + dataframe['date'].apply(lambda x: x.hour).between( + self.buy_hour_min.value, self.buy_hour_max.value) + ), + + 'buy'] = 1 + + return dataframe + + def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + dataframe.loc[ + ( + dataframe['date'].apply(lambda x: x.hour).between( + self.sell_hour_min.value, self.sell_hour_max.value) + ), + 'sell'] = 1 + return dataframe From 92c4170e7cae497e11ced4d10684348310690efe Mon Sep 17 00:00:00 2001 From: Masoud Azizi Date: Thu, 18 Nov 2021 18:41:06 +0330 Subject: [PATCH 2/3] apply ~> dt.hour --- user_data/strategies/Khayyam.py | 86 +++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 19 deletions(-) diff --git a/user_data/strategies/Khayyam.py b/user_data/strategies/Khayyam.py index 05a9885..4ff898c 100644 --- a/user_data/strategies/Khayyam.py +++ b/user_data/strategies/Khayyam.py @@ -1,60 +1,108 @@ # Khayyam Strategy # In this strategy we try to find the best hours to buy and sell in a day.(in hourly timeframe) # Cuz of that you should just use 1h timeframe on this strategy. -# Name of this strategy come from the Omar khayyam who was a Persian polymath, -# mathematician, astronomer, philosopher, and poet! +# Name of this strategy come from the Omar khayyam who was a Persian polymath, +# mathematician, astronomer, philosopher, and poet! # https://en.wikipedia.org/wiki/Omar_Khayyam # Author: @Mablue (Masoud Azizi) # github: https://github.com/mablue/ -# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --strategy Khayyam +# * RUN LIVE AFTER HYPEROPT! +# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --strategy Khayyam -e 200 -from freqtrade.strategy.hyper import IntParameter + +from freqtrade.strategy import IntParameter from freqtrade.strategy import IStrategy from pandas import DataFrame # -------------------------------- # Add your lib to import here +# No need to These imports. just for who want to add more conditions: +# import talib.abstract as ta +# import freqtrade.vendor.qtpylib.indicators as qtpylib class Khayyam(IStrategy): + # SHIB/USDT, 1000$x1:100days + # 158/1000: 51 trades. 29/19/3 Wins/Draws/Losses. Avg profit 4.02%. Median profit 2.48%. Total profit 4867.53438466 USDT ( 486.75%). Avg duration 1 day, 19:38:00 min. Objective: -4.17276 + # buy_params = {"buy_hour_max": 18,"buy_hour_min": 7,} + # sell_params = {"sell_hour_max": 9,"sell_hour_min": 21,} + # minimal_roi = {"0": 0.18,"171": 0.155,"315": 0.075,"1035": 0} + # stoploss = -0.292 + + # SHIB/USDT, 1000$x1:100days + # 36/1000: 113 trades. 55/14/44 Wins/Draws/Losses. Avg profit 2.06%. Median profit 0.00%. Total profit 5126.14785426 USDT ( 512.61%). Avg duration 16:48:00 min. Objective: -4.57837 + # buy_params = {"buy_hour_max": 21,"buy_hour_min": 6,} + # sell_params = {"sell_hour_max": 6,"sell_hour_min": 4,} + # minimal_roi = {"0": 0.247,"386": 0.186,"866": 0.052,"1119": 0} + # stoploss = -0.302 + + # SAND/USDT, 1000$x1:100days + # 72/1000: 158 trades. 67/13/78 Wins/Draws/Losses. Avg profit 1.37%. Median profit 0.00%. Total profit 4274.73622346 USDT ( 427.47%). Avg duration 13:50:00 min. Objective: -4.87331 + # buy_params = {"buy_hour_max": 23,"buy_hour_min": 4,} + # sell_params = {"sell_hour_max": 23,"sell_hour_min": 3,} + # minimal_roi = {"0": 0.482,"266": 0.191,"474": 0.09,"1759": 0} + # stoploss = -0.05 + + # KDA/USDT, 1000$x1:100days + # 7/1000: 65 trades. 40/23/2 Wins/Draws/Losses. Avg profit 6.42%. Median profit 7.59%. Total profit 41120.00939125 USDT ( 4112.00%). Avg duration 1 day, 9:40:00 min. Objective: -8.46089 + # buy_params = {"buy_hour_max": 22,"buy_hour_min": 9,} + # sell_params = {"sell_hour_max": 1,"sell_hour_min": 7,} + # minimal_roi = {"0": 0.517,"398": 0.206,"1003": 0.076,"1580": 0} + # stoploss = -0.338 + + # {KDA/USDT, BTC/USDT, DOGE/USDT, SAND/USDT, ETH/USDT, SOL/USDT}, 1000$x1:100days, ShuffleFilter42 + # 56/1000: 63 trades. 41/19/3 Wins/Draws/Losses. Avg profit 4.60%. Median profit 8.89%. Total profit 11596.50333022 USDT ( 1159.65%). Avg duration 1 day, 14:46:00 min. Objective: -5.76694 + + # Buy hyperspace params: + buy_params = { + "buy_hour_max": 24, + "buy_hour_min": 4, + } + + # Sell hyperspace params: + sell_params = { + "sell_hour_max": 21, + "sell_hour_min": 22, + } + # ROI table: minimal_roi = { - "0": 0.434, - "391": 0.116, - "511": 0.025, - "1919": 0 + "0": 0.528, + "169": 0.113, + "528": 0.089, + "1837": 0 } # Stoploss: - stoploss = -0.29 + stoploss = -0.296 # Optimal timeframe timeframe = '1h' - buy_hour_max = IntParameter(0, 24, default=24, space='buy') - buy_hour_min = IntParameter(0, 24, default=11, space='buy') + buy_hour_min = IntParameter(0, 24, default=1, space='buy') + buy_hour_max = IntParameter(0, 24, default=0, space='buy') - sell_hour_max = IntParameter(0, 24, default=6, space='sell') - sell_hour_min = IntParameter(0, 24, default=15, space='sell') + sell_hour_min = IntParameter(0, 24, default=1, space='sell') + sell_hour_max = IntParameter(0, 24, default=0, space='sell') def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + dataframe['hour'] = dataframe['date'].dt.hour return dataframe def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + min, max = self.buy_hour_min.value, self.buy_hour_max.value dataframe.loc[ ( - dataframe['date'].apply(lambda x: x.hour).between( - self.buy_hour_min.value, self.buy_hour_max.value) + (dataframe['hour'].between(min, max)) ), - 'buy'] = 1 return dataframe def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + min, max = self.sell_hour_min.value, self.sell_hour_max.value dataframe.loc[ ( - dataframe['date'].apply(lambda x: x.hour).between( - self.sell_hour_min.value, self.sell_hour_max.value) + (dataframe['hour'].between(min, max)) ), - 'sell'] = 1 + 'buy'] = 1 return dataframe From 0fd380d1f86961baf0f874c73658fb4dc95d4ca2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 20 Nov 2021 08:06:47 +0100 Subject: [PATCH 3/3] Name strategy to reflect how it actually works. --- .../{Khayyam.py => HourBasedStrategy.py} | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) rename user_data/strategies/{Khayyam.py => HourBasedStrategy.py} (90%) diff --git a/user_data/strategies/Khayyam.py b/user_data/strategies/HourBasedStrategy.py similarity index 90% rename from user_data/strategies/Khayyam.py rename to user_data/strategies/HourBasedStrategy.py index 4ff898c..c8c30db 100644 --- a/user_data/strategies/Khayyam.py +++ b/user_data/strategies/HourBasedStrategy.py @@ -1,18 +1,15 @@ -# Khayyam Strategy +# Hour Strategy # In this strategy we try to find the best hours to buy and sell in a day.(in hourly timeframe) -# Cuz of that you should just use 1h timeframe on this strategy. -# Name of this strategy come from the Omar khayyam who was a Persian polymath, -# mathematician, astronomer, philosopher, and poet! -# https://en.wikipedia.org/wiki/Omar_Khayyam +# Because of that you should just use 1h timeframe on this strategy. # Author: @Mablue (Masoud Azizi) # github: https://github.com/mablue/ -# * RUN LIVE AFTER HYPEROPT! -# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --strategy Khayyam -e 200 +# Requires hyperopt before running. +# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --strategy HourBasedStrategy -e 200 -from freqtrade.strategy import IntParameter -from freqtrade.strategy import IStrategy +from freqtrade.strategy import IntParameter, IStrategy from pandas import DataFrame + # -------------------------------- # Add your lib to import here # No need to These imports. just for who want to add more conditions: @@ -20,7 +17,7 @@ from pandas import DataFrame # import freqtrade.vendor.qtpylib.indicators as qtpylib -class Khayyam(IStrategy): +class HourBasedStrategy(IStrategy): # SHIB/USDT, 1000$x1:100days # 158/1000: 51 trades. 29/19/3 Wins/Draws/Losses. Avg profit 4.02%. Median profit 2.48%. Total profit 4867.53438466 USDT ( 486.75%). Avg duration 1 day, 19:38:00 min. Objective: -4.17276 # buy_params = {"buy_hour_max": 18,"buy_hour_min": 7,} @@ -73,7 +70,7 @@ class Khayyam(IStrategy): } # Stoploss: - stoploss = -0.296 + stoploss = -0.10 # Optimal timeframe timeframe = '1h'