diff --git a/user_data/hyperopts/mabStraHo.py b/user_data/hyperopts/mabStraHo.py deleted file mode 100644 index 9e10968..0000000 --- a/user_data/hyperopts/mabStraHo.py +++ /dev/null @@ -1,95 +0,0 @@ -# by: Mablue (Masoud Azizi) - -# --- Do not remove these libs --- -from functools import reduce -from typing import Any, Callable, Dict, List - -import numpy as np # noqa -import pandas as pd # noqa -from pandas import DataFrame -from skopt.space import Categorical, Dimension, Integer, Real # noqa - -from freqtrade.optimize.hyperopt_interface import IHyperOpt - -# -------------------------------- -# Add your lib to import here -import talib.abstract as ta # noqa -import freqtrade.vendor.qtpylib.indicators as qtpylib - - -class mabStraHo(IHyperOpt): - - @staticmethod - def indicator_space() -> List[Dimension]: - """ - Define your Hyperopt space for searching buy strategy parameters. - """ - return [ - Real(0, 1, name='buy-div-min'), - Real(0, 1, name='buy-div-max'), - ] - - @staticmethod - def buy_strategy_generator(params: Dict[str, Any]) -> Callable: - """ - Define the buy strategy parameters to be used by Hyperopt. - """ - def populate_buy_trend(dataframe: DataFrame, metadata: dict) -> DataFrame: - """ - Buy strategy Hyperopt will build and use. - """ - conditions = [] - # GUARDS AND TRENDS - - # div result limited to 0~1 so allways in buy position slowMa is lower than fastMa - # optimum number will calculate by this two lines - conditions.append(dataframe['buy-fastMA'].div(dataframe['buy-slowMA']) - > params['buy-div-min']) - conditions.append(dataframe['buy-fastMA'].div(dataframe['buy-slowMA']) - < params['buy-div-max']) - - if conditions: - dataframe.loc[ - reduce(lambda x, y: x & y, conditions), - 'buy'] = 1 - - return dataframe - - return populate_buy_trend - - @staticmethod - def sell_indicator_space() -> List[Dimension]: - """ - Define your Hyperopt space for searching sell strategy parameters. - """ - return [ - Real(0, 1, name='sell-div-min'), - Real(0, 1, name='sell-div-max'), - ] - - @staticmethod - def sell_strategy_generator(params: Dict[str, Any]) -> Callable: - """ - Define the sell strategy parameters to be used by Hyperopt. - """ - def populate_sell_trend(dataframe: DataFrame, metadata: dict) -> DataFrame: - """ - Sell strategy Hyperopt will build and use. - """ - conditions = [] - - # GUARDS AND TRENDS - - conditions.append(dataframe['sell-slowMA'].div(dataframe['sell-fastMA']) - > params['sell-div-min']) - conditions.append(dataframe['sell-slowMA'].div(dataframe['sell-fastMA']) - < params['sell-div-max']) - - if conditions: - dataframe.loc[ - reduce(lambda x, y: x & y, conditions), - 'sell'] = 1 - - return dataframe - - return populate_sell_trend diff --git a/user_data/strategies/mabStra.py b/user_data/strategies/mabStra.py index 0512d14..d2615cc 100644 --- a/user_data/strategies/mabStra.py +++ b/user_data/strategies/mabStra.py @@ -1,6 +1,10 @@ -# author: Masoud Azizi @mablue +# Author: @Mablue (Masoud Azizi) +# github: https://github.com/mablue/ +# IMPORTANT: DO NOT USE IT WITHOUT HYPEROPT: +# freqtrade hyperopt --hyperopt mabStraHo --hyperopt-loss SharpeHyperOptLoss --spaces all --strategy mabStra --config config.json -e 100 # --- Do not remove these libs --- +from freqtrade.strategy.hyper import IntParameter, DecimalParameter from freqtrade.strategy.interface import IStrategy from pandas import DataFrame # -------------------------------- @@ -9,58 +13,54 @@ from pandas import DataFrame import talib.abstract as ta import freqtrade.vendor.qtpylib.indicators as qtpylib -FTF, STF = 5, 10 - class mabStra(IStrategy): + # buy params + buy_mojo_ma_timeframe = IntParameter(2, 100, default=7, space='buy') + buy_fast_ma_timeframe = IntParameter(2, 100, default=14, space='buy') + buy_slow_ma_timeframe = IntParameter(2, 100, default=28, space='buy') + buy_div_max = DecimalParameter(0, 2, decimals=4, default=2.25446, space='buy') + buy_div_min = DecimalParameter(0, 2, decimals=4, default=0.29497, space='buy') + # sell params + sell_mojo_ma_timeframe = IntParameter(2, 100, default=7, space='sell') + sell_fast_ma_timeframe = IntParameter(2, 100, default=14, space='sell') + sell_slow_ma_timeframe = IntParameter(2, 100, default=28, space='sell') + sell_div_max = DecimalParameter(0, 2, decimals=4, default=1.54593, space='sell') + sell_div_min = DecimalParameter(0, 2, decimals=4, default=2.81436, space='sell') - # 100/100: 727 trades. 486/191/50 Wins/Draws/Losses. Avg profit 3.53 % . Median profit 5.97 % . Total profit 1502.52014358 USDT (2566.80Σ %). Avg duration 1396.1 min. Objective: -15.62092 + stoploss = -0.1 - # Buy hyperspace params: - buy_params = { - 'buy-div-max': 0.96451, 'buy-div-min': 0.22313 - } - - # Sell hyperspace params: - sell_params = { - 'sell-div-max': 0.75476, 'sell-div-min': 0.16599 - } - - # ROI table: - minimal_roi = { - "0": 0.45574, - "307": 0.21971, - "428": 0.06762, - "1387": 0 - } - - # Stoploss: - stoploss = -0.34773 - - # Trailing stop: - trailing_stop = True - trailing_stop_positive = 0.01573 - trailing_stop_positive_offset = 0.06651 - trailing_only_offset_is_reached = True # Optimal timeframe use it in your config - timeframe = '1h' + timeframe = '4h' def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # SMA - ex Moving Average - dataframe['buy-fastMA'] = ta.SMA(dataframe, timeperiod=FTF) - dataframe['buy-slowMA'] = ta.SMA(dataframe, timeperiod=STF) - dataframe['sell-fastMA'] = ta.SMA(dataframe, timeperiod=FTF) - dataframe['sell-slowMA'] = ta.SMA(dataframe, timeperiod=STF) + dataframe['buy-mojoMA'] = ta.SMA(dataframe, + timeperiod=self.buy_mojo_ma_timeframe.value) + dataframe['buy-fastMA'] = ta.SMA(dataframe, + timeperiod=self.buy_fast_ma_timeframe.value) + dataframe['buy-slowMA'] = ta.SMA(dataframe, + timeperiod=self.buy_slow_ma_timeframe.value) + dataframe['sell-mojoMA'] = ta.SMA(dataframe, + timeperiod=self.sell_mojo_ma_timeframe.value) + dataframe['sell-fastMA'] = ta.SMA(dataframe, + timeperiod=self.sell_fast_ma_timeframe.value) + dataframe['sell-slowMA'] = ta.SMA(dataframe, + timeperiod=self.sell_slow_ma_timeframe.value) return dataframe def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe.loc[ ( + (dataframe['buy-mojoMA'].div(dataframe['buy-fastMA']) + > self.buy_div_min.value) & + (dataframe['buy-mojoMA'].div(dataframe['buy-fastMA']) + < self.buy_div_max.value) & (dataframe['buy-fastMA'].div(dataframe['buy-slowMA']) - > self.buy_params['buy-div-min']) & + > self.buy_div_min.value) & (dataframe['buy-fastMA'].div(dataframe['buy-slowMA']) - < self.buy_params['buy-div-max']) + < self.buy_div_max.value) ), 'buy'] = 1 @@ -69,10 +69,14 @@ class mabStra(IStrategy): def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe.loc[ ( + (dataframe['sell-fastMA'].div(dataframe['sell-mojoMA']) + > self.sell_div_min.value) & + (dataframe['sell-fastMA'].div(dataframe['sell-mojoMA']) + < self.sell_div_max.value) & (dataframe['sell-slowMA'].div(dataframe['sell-fastMA']) - > self.sell_params['sell-div-min']) & + > self.sell_div_min.value) & (dataframe['sell-slowMA'].div(dataframe['sell-fastMA']) - < self.sell_params['sell-div-max']) + < self.sell_div_max.value) ), 'sell'] = 1 return dataframe