first
This commit is contained in:
0
.env/bin/user_data/hyperopts/.gitkeep
Normal file
0
.env/bin/user_data/hyperopts/.gitkeep
Normal file
0
.env/bin/user_data/hyperopts/__init__.py
Normal file
0
.env/bin/user_data/hyperopts/__init__.py
Normal file
168
.env/bin/user_data/hyperopts/advanced.py
Normal file
168
.env/bin/user_data/hyperopts/advanced.py
Normal file
@@ -0,0 +1,168 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 advanced(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(dataframe['mfi'] < params['mfi-value'])
|
||||
if params.get('fastd-enabled'):
|
||||
conditions.append(dataframe['fastd'] < params['fastd-value'])
|
||||
if params.get('adx-enabled'):
|
||||
conditions.append(dataframe['adx'] > params['adx-value'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(dataframe['rsi'] < params['rsi-value'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'bb_lower':
|
||||
conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'sar_reversal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['sar']
|
||||
))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 25, name='mfi-value'),
|
||||
Integer(15, 45, name='fastd-value'),
|
||||
Integer(20, 50, name='adx-value'),
|
||||
Integer(20, 40, name='rsi-value'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='fastd-enabled'),
|
||||
Categorical([True, False], name='adx-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['bb_lower', 'macd_cross_signal', 'sar_reversal'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('sell-mfi-enabled'):
|
||||
conditions.append(dataframe['mfi'] > params['sell-mfi-value'])
|
||||
if params.get('sell-fastd-enabled'):
|
||||
conditions.append(dataframe['fastd'] > params['sell-fastd-value'])
|
||||
if params.get('sell-adx-enabled'):
|
||||
conditions.append(dataframe['adx'] < params['sell-adx-value'])
|
||||
if params.get('sell-rsi-enabled'):
|
||||
conditions.append(dataframe['rsi'] > params['sell-rsi-value'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'sell-trigger' in params:
|
||||
if params['sell-trigger'] == 'sell-bb_upper':
|
||||
conditions.append(dataframe['close'] > dataframe['bb_upperband'])
|
||||
if params['sell-trigger'] == 'sell-macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macdsignal'], dataframe['macd']
|
||||
))
|
||||
if params['sell-trigger'] == 'sell-sar_reversal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['sar'], dataframe['close']
|
||||
))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(75, 100, name='sell-mfi-value'),
|
||||
Integer(50, 100, name='sell-fastd-value'),
|
||||
Integer(50, 100, name='sell-adx-value'),
|
||||
Integer(60, 100, name='sell-rsi-value'),
|
||||
Categorical([True, False], name='sell-mfi-enabled'),
|
||||
Categorical([True, False], name='sell-fastd-enabled'),
|
||||
Categorical([True, False], name='sell-adx-enabled'),
|
||||
Categorical([True, False], name='sell-rsi-enabled'),
|
||||
Categorical(['sell-bb_upper',
|
||||
'sell-macd_cross_signal',
|
||||
'sell-sar_reversal'], name='sell-trigger')
|
||||
]
|
||||
304
.env/bin/user_data/hyperopts/advanced_hyper.py
Normal file
304
.env/bin/user_data/hyperopts/advanced_hyper.py
Normal file
@@ -0,0 +1,304 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
# isort: skip_file
|
||||
# --- 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 AdvancedSampleHyperOpt(IHyperOpt):
|
||||
"""
|
||||
This is a sample hyperopt to inspire you.
|
||||
Feel free to customize it.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Rename the class name to some unique name.
|
||||
- Add any methods you want to build your hyperopt.
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need the
|
||||
'roi' and the 'stoploss' spaces that differ from the defaults offered by Freqtrade.
|
||||
|
||||
This sample illustrates how to override these methods.
|
||||
"""
|
||||
# @staticmethod
|
||||
# def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
# """
|
||||
# This method can also be loaded from the strategy, if it doesn't exist in the hyperopt class.
|
||||
# """
|
||||
# dataframe['adx'] = ta.ADX(dataframe)
|
||||
# macd = ta.MACD(dataframe)
|
||||
# dataframe['macd'] = macd['macd']
|
||||
# dataframe['macdsignal'] = macd['macdsignal']
|
||||
# dataframe['mfi'] = ta.MFI(dataframe)
|
||||
# dataframe['rsi'] = ta.RSI(dataframe)
|
||||
# stoch_fast = ta.STOCHF(dataframe)
|
||||
# dataframe['fastd'] = stoch_fast['fastd']
|
||||
# dataframe['minus_di'] = ta.MINUS_DI(dataframe)
|
||||
# # Bollinger bands
|
||||
# bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
|
||||
# dataframe['bb_lowerband'] = bollinger['lower']
|
||||
# dataframe['bb_upperband'] = bollinger['upper']
|
||||
# dataframe['sar'] = ta.SAR(dataframe)
|
||||
# return dataframe
|
||||
|
||||
@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
|
||||
if 'mfi-enabled' in params and params['mfi-enabled']:
|
||||
conditions.append(dataframe['mfi'] < params['mfi-value'])
|
||||
if 'fastd-enabled' in params and params['fastd-enabled']:
|
||||
conditions.append(dataframe['fastd'] < params['fastd-value'])
|
||||
if 'adx-enabled' in params and params['adx-enabled']:
|
||||
conditions.append(dataframe['adx'] > params['adx-value'])
|
||||
if 'rsi-enabled' in params and params['rsi-enabled']:
|
||||
conditions.append(dataframe['rsi'] < params['rsi-value'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'bb_midd':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['close'], dataframe['bb_middleband']))
|
||||
if params['trigger'] == 'bb_low':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['close'], dataframe['bb_lowerband']))
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
|
||||
# Check that volume is not 0
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching strategy parameters
|
||||
"""
|
||||
return [
|
||||
Integer(10, 25, name='mfi-value'),
|
||||
Integer(15, 45, name='fastd-value'),
|
||||
Integer(20, 50, name='adx-value'),
|
||||
Integer(20, 40, name='rsi-value'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='fastd-enabled'),
|
||||
Categorical([True, False], name='adx-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['bb_lower', 'macd_cross_signal', 'sar_reversal'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
"""
|
||||
# print(params)
|
||||
conditions = []
|
||||
# GUARDS AND TRENDS
|
||||
if 'sell-mfi-enabled' in params and params['sell-mfi-enabled']:
|
||||
conditions.append(dataframe['mfi'] > params['sell-mfi-value'])
|
||||
if 'sell-fastd-enabled' in params and params['sell-fastd-enabled']:
|
||||
conditions.append(dataframe['fastd'] > params['sell-fastd-value'])
|
||||
if 'sell-adx-enabled' in params and params['sell-adx-enabled']:
|
||||
conditions.append(dataframe['adx'] < params['sell-adx-value'])
|
||||
if 'sell-rsi-enabled' in params and params['sell-rsi-enabled']:
|
||||
conditions.append(dataframe['rsi'] > params['sell-rsi-value'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'sell-trigger' in params:
|
||||
if params['sell-trigger'] == 'sell-bb_upper':
|
||||
conditions.append(dataframe['close'] > dataframe['bb_upperband'])
|
||||
if params['sell-trigger'] == 'sell-macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macdsignal'], dataframe['macd']
|
||||
))
|
||||
if params['sell-trigger'] == 'sell-sar_reversal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['sar'], dataframe['close']
|
||||
))
|
||||
|
||||
# Check that volume is not 0
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters
|
||||
"""
|
||||
return [
|
||||
Integer(75, 100, name='sell-mfi-value'),
|
||||
Integer(50, 100, name='sell-fastd-value'),
|
||||
Integer(50, 100, name='sell-adx-value'),
|
||||
Integer(60, 100, name='sell-rsi-value'),
|
||||
Categorical([True, False], name='sell-mfi-enabled'),
|
||||
Categorical([True, False], name='sell-fastd-enabled'),
|
||||
Categorical([True, False], name='sell-adx-enabled'),
|
||||
Categorical([True, False], name='sell-rsi-enabled'),
|
||||
Categorical(['sell-bb_upper',
|
||||
'sell-macd_cross_signal',
|
||||
'sell-sar_reversal'], name='sell-trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 120, name='roi_t1'),
|
||||
Integer(10, 60, name='roi_t2'),
|
||||
Integer(10, 40, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.35, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
|
||||
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
"""
|
||||
Based on TA indicators.
|
||||
Can be a copy of the corresponding method from the strategy,
|
||||
or will be loaded from the strategy.
|
||||
Must align to populate_indicators used (either from this File, or from the strategy)
|
||||
Only used when --spaces does not include buy
|
||||
"""
|
||||
dataframe.loc[
|
||||
(
|
||||
(dataframe['close'] < dataframe['bb_lowerband']) &
|
||||
(dataframe['mfi'] < 16) &
|
||||
(dataframe['adx'] > 25) &
|
||||
(dataframe['rsi'] < 21)
|
||||
),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
"""
|
||||
Based on TA indicators.
|
||||
Can be a copy of the corresponding method from the strategy,
|
||||
or will be loaded from the strategy.
|
||||
Must align to populate_indicators used (either from this File, or from the strategy)
|
||||
Only used when --spaces does not include sell
|
||||
"""
|
||||
dataframe.loc[
|
||||
(
|
||||
(qtpylib.crossed_above(
|
||||
dataframe['macdsignal'], dataframe['macd']
|
||||
)) &
|
||||
(dataframe['fastd'] > 54)
|
||||
),
|
||||
'sell'] = 1
|
||||
return dataframe
|
||||
168
.env/bin/user_data/hyperopts/full_hyper.py
Normal file
168
.env/bin/user_data/hyperopts/full_hyper.py
Normal file
@@ -0,0 +1,168 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 full_hyper(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(dataframe['mfi'] < params['mfi-value'])
|
||||
if params.get('fastd-enabled'):
|
||||
conditions.append(dataframe['fastd'] < params['fastd-value'])
|
||||
if params.get('adx-enabled'):
|
||||
conditions.append(dataframe['adx'] > params['adx-value'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(dataframe['rsi'] < params['rsi-value'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'bb_lower':
|
||||
conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'sar_reversal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['sar']
|
||||
))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 25, name='mfi-value'),
|
||||
Integer(15, 45, name='fastd-value'),
|
||||
Integer(20, 50, name='adx-value'),
|
||||
Integer(20, 40, name='rsi-value'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='fastd-enabled'),
|
||||
Categorical([True, False], name='adx-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['bb_lower', 'macd_cross_signal', 'sar_reversal'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('sell-mfi-enabled'):
|
||||
conditions.append(dataframe['mfi'] > params['sell-mfi-value'])
|
||||
if params.get('sell-fastd-enabled'):
|
||||
conditions.append(dataframe['fastd'] > params['sell-fastd-value'])
|
||||
if params.get('sell-adx-enabled'):
|
||||
conditions.append(dataframe['adx'] < params['sell-adx-value'])
|
||||
if params.get('sell-rsi-enabled'):
|
||||
conditions.append(dataframe['rsi'] > params['sell-rsi-value'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'sell-trigger' in params:
|
||||
if params['sell-trigger'] == 'sell-bb_upper':
|
||||
conditions.append(dataframe['close'] > dataframe['bb_upperband'])
|
||||
if params['sell-trigger'] == 'sell-macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macdsignal'], dataframe['macd']
|
||||
))
|
||||
if params['sell-trigger'] == 'sell-sar_reversal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['sar'], dataframe['close']
|
||||
))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(75, 100, name='sell-mfi-value'),
|
||||
Integer(50, 100, name='sell-fastd-value'),
|
||||
Integer(50, 100, name='sell-adx-value'),
|
||||
Integer(60, 100, name='sell-rsi-value'),
|
||||
Categorical([True, False], name='sell-mfi-enabled'),
|
||||
Categorical([True, False], name='sell-fastd-enabled'),
|
||||
Categorical([True, False], name='sell-adx-enabled'),
|
||||
Categorical([True, False], name='sell-rsi-enabled'),
|
||||
Categorical(['sell-bb_upper',
|
||||
'sell-macd_cross_signal',
|
||||
'sell-sar_reversal'], name='sell-trigger')
|
||||
]
|
||||
393
.env/bin/user_data/hyperopts/hyper1.py
Normal file
393
.env/bin/user_data/hyperopts/hyper1.py
Normal file
@@ -0,0 +1,393 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper1(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('tsf_long-enabled'):
|
||||
conditions.append((dataframe['close'] - dataframe['tsf_long']) > params['tsf_long-value'])
|
||||
if params.get('tsf_mid-enabled'):
|
||||
conditions.append((dataframe['tsf_mid'] - dataframe['close']) > params['tsf_mid-value'])
|
||||
if params.get('tsf_short-enabled'):
|
||||
conditions.append((dataframe['tsf_short'] - dataframe['close']) > params['tsf_short-value'])
|
||||
if params.get('angle_short-enabled'):
|
||||
conditions.append(dataframe['angle_short'] > params['angle_short-value'])
|
||||
if params.get('angle_mid-enabled'):
|
||||
conditions.append(dataframe['angle_mid'] > params['angle_mid-value'])
|
||||
if params.get('angle_long-enabled'):
|
||||
conditions.append(dataframe['angle_long'] > params['angle_long-value'])
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value'] < dataframe['correl_h_l'])
|
||||
if params.get('correl_close_last_close-enabled'):
|
||||
conditions.append(params['correl_close_last_close-value'] < dataframe['correl_close_last_close'])
|
||||
if params.get('correl_tsf_long_close-enabled'):
|
||||
conditions.append(params['correl_tsf_long_close-value'] < dataframe['correl_tsf_long_close'])
|
||||
if params.get('correl_tsf_mid_close-enabled'):
|
||||
conditions.append(params['correl_tsf_mid_close-value'] < dataframe['correl_tsf_mid_close'])
|
||||
if params.get('correl_tsf_short_close-enabled'):
|
||||
conditions.append(params['correl_tsf_short_close-value'] < dataframe['correl_tsf_short_close'])
|
||||
if params.get('correl_angle_short_close-enabled'):
|
||||
conditions.append(params['correl_angle_short_close-value'] < dataframe['correl_angle_short_close'])
|
||||
if params.get('correl_angle_mid_close-enabled'):
|
||||
conditions.append(params['correl_angle_mid_close-value'] < dataframe['correl_angle_mid_close'])
|
||||
if params.get('correl_angle_long_close-enabled'):
|
||||
conditions.append(params['correl_angle_long_close-value'] < dataframe['correl_angle_long_close'])
|
||||
if params.get('correl_hist_close-enabled'):
|
||||
conditions.append(params['correl_hist_close-value'] < dataframe['correl_hist_close'])
|
||||
if params.get('correl_mfi_close-enabled'):
|
||||
conditions.append(params['correl_mfi_close-value'] < dataframe['correl_mfi_close'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value'] < dataframe['mfi'])
|
||||
if params.get('ema-enabled'):
|
||||
conditions.append(params['ema-value'] < (dataframe['close'] - dataframe['ema']))
|
||||
if params.get('ema_bol-enabled'):
|
||||
conditions.append(params['ema_bol-value'] < (dataframe['ema'] - dataframe['middleband']))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macdhist-value'] < dataframe['macdhist'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_low':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['lowerband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'ma_cross':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['ma'], dataframe['ema']))
|
||||
if params['trigger'] == 'ema_cross':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['ema']))
|
||||
if params['trigger'] == 'mfi':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['mfi'], 25))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-100, 100, name='tsf_long-value'),
|
||||
Integer(-100, 100, name='tsf_mid-value'),
|
||||
Integer(-100, 100, name='tsf_short-value'),
|
||||
Integer(-50, 50, name='angle_short-value'),
|
||||
Integer(-50, 50, name='angle_long-value'),
|
||||
Integer(-50, 50, name='angle_mid-value'),
|
||||
Real(0, 1, name='correl_h_l-value'),
|
||||
Real(-1, 1, name='correl_close_last_close-value'),
|
||||
Real(0, 1, name='correl_tsf_long_close-value'),
|
||||
Real(-1, 1, name='correl_tsf_mid_close-value'),
|
||||
Real(-1, 1, name='correl_tsf_short_close-value'),
|
||||
Real(-1, 1, name='correl_angle_short_close-value'),
|
||||
Real(0, 1, name='correl_angle_mid_close-value'),
|
||||
Real(0, 1, name='correl_angle_long_close-value'),
|
||||
Real(-1, 1, name='correl_hist_close-value'),
|
||||
Real(-1, 1, name='correl_mfi_close-value'),
|
||||
Integer(10, 60, name='mfi-value'),
|
||||
Integer(-50, 50, name='ema-value'),
|
||||
Integer(-50, 50, name='ema_bol-value'),
|
||||
Integer(-1, 5, name='macdhist-value'),
|
||||
Categorical([True, False], name='angle_short-enabled'),
|
||||
Categorical([True, False], name='angle_long-enabled'),
|
||||
Categorical([True, False], name='angle_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_long-enabled'),
|
||||
Categorical([True, False], name='tsf_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_short-enabled'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='correl_close_last_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_mfi_close-enabled'),
|
||||
Categorical([True, False], name='correl_hist_close-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='ema-enabled'),
|
||||
Categorical([True, False], name='ema_bol-enabled'),
|
||||
Categorical(['mfi', 'macd_cross_signal', 'bol_low', 'bol_mid', 'ma_cross'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('tsf_long-enabled'):
|
||||
conditions.append((dataframe['tsf_long'] - dataframe['close']) > params['tsf_long-value_sell'])
|
||||
if params.get('tsf_mid-enabled'):
|
||||
conditions.append((dataframe['tsf_mid'] - dataframe['close']) > params['tsf_mid-value_sell'])
|
||||
if params.get('tsf_short-enabled'):
|
||||
conditions.append((dataframe['tsf_short'] - dataframe['close']) > params['tsf_short-value_sell'])
|
||||
if params.get('angle_short-enabled'):
|
||||
conditions.append(dataframe['angle_short'] > params['angle_short-value_sell'])
|
||||
if params.get('angle_mid-enabled'):
|
||||
conditions.append(dataframe['angle_mid'] > params['angle_mid-value_sell'])
|
||||
if params.get('angle_long-enabled'):
|
||||
conditions.append(dataframe['angle_long'] > params['angle_long-value_sell'])
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value_sell'] < dataframe['correl_h_l'])
|
||||
if params.get('correl_close_last_close-enabled'):
|
||||
conditions.append(params['correl_close_last_close-value_sell'] < dataframe['correl_close_last_close'])
|
||||
if params.get('correl_tsf_long_close-enabled'):
|
||||
conditions.append(params['correl_tsf_long_close-value_sell'] < dataframe['correl_tsf_long_close'])
|
||||
if params.get('correl_tsf_mid_close-enabled'):
|
||||
conditions.append(params['correl_tsf_mid_close-value_sell'] < dataframe['correl_tsf_mid_close'])
|
||||
if params.get('correl_tsf_short_close-enabled'):
|
||||
conditions.append(params['correl_tsf_short_close-value_sell'] < dataframe['correl_tsf_short_close'])
|
||||
if params.get('correl_angle_short_close-enabled'):
|
||||
conditions.append(params['correl_angle_short_close-value_sell'] < dataframe['correl_angle_short_close'])
|
||||
if params.get('correl_angle_mid_close-enabled'):
|
||||
conditions.append(params['correl_angle_mid_close-value_sell'] < dataframe['correl_angle_mid_close'])
|
||||
if params.get('correl_angle_long_close-enabled'):
|
||||
conditions.append(params['correl_angle_long_close-value_sell'] < dataframe['correl_angle_long_close'])
|
||||
if params.get('correl_hist_close-enabled'):
|
||||
conditions.append(params['correl_hist_close-value_sell'] < dataframe['correl_hist_close'])
|
||||
if params.get('correl_mfi_close-enabled'):
|
||||
conditions.append(params['correl_mfi_close-value_sell'] < dataframe['correl_mfi_close'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value_sell'] > dataframe['mfi'])
|
||||
if params.get('ema-enabled'):
|
||||
conditions.append(params['ema-value_sell'] < (dataframe['ema'] - dataframe['close']))
|
||||
if params.get('ema_bol-enabled'):
|
||||
conditions.append(params['ema_bol-value_sell'] < (dataframe['middleband'] - dataframe['ema']))
|
||||
conditions.append(params['macdhist-value_sell'] > dataframe['macdhist'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_high':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['upperband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'ma_cross':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['ema'], dataframe['middleband']))
|
||||
if params['trigger'] == 'ema_cross':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['ema']))
|
||||
if params['trigger'] == 'mfi':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['mfi'], 60))
|
||||
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-100, 100, name='tsf_long-value_sell'),
|
||||
Integer(-100, 100, name='tsf_mid-value_sell'),
|
||||
Integer(-100, 100, name='tsf_short-value_sell'),
|
||||
Integer(-50, 50, name='angle_short-value_sell'),
|
||||
Integer(-50, 50, name='angle_long-value_sell'),
|
||||
Integer(-50, 50, name='angle_mid-value_sell'),
|
||||
Real(-1, 1, name='correl_h_l-value_sell'),
|
||||
Real(-1, 1, name='correl_close_last_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_long_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_mid_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_short_close-value_sell'),
|
||||
Real(-1, 1, name='correl_angle_short_close-value_sell'),
|
||||
Real(-1, 1, name='correl_angle_mid_close-value_sell'),
|
||||
Real(-1, 1, name='correl_angle_long_close-value_sell'),
|
||||
Real(-1, 1, name='correl_hist_close-value_sell'),
|
||||
Real(-1, 1, name='correl_mfi_close-value_sell'),
|
||||
Integer(40, 100, name='mfi-value_sell'),
|
||||
Integer(-5, 50, name='ema-value_sell'),
|
||||
Integer(-5, 50, name='ema_bol-value_sell'),
|
||||
Integer(-10, 20, name='macdhist-value_sell'),
|
||||
Categorical([True, False], name='angle_short-enabled'),
|
||||
Categorical([True, False], name='angle_long-enabled'),
|
||||
Categorical([True, False], name='angle_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_long-enabled'),
|
||||
Categorical([True, False], name='tsf_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_short-enabled'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='correl_close_last_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_mfi_close-enabled'),
|
||||
Categorical([True, False], name='correl_hist_close-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='ema-enabled'),
|
||||
Categorical([True, False], name='ema_bol-enabled'),
|
||||
Categorical(['mfi', 'macd_cross_signal', 'bol_high', 'bol_mid', 'ma_cross'], name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 120, name='roi_t1'),
|
||||
Integer(10, 60, name='roi_t2'),
|
||||
Integer(10, 40, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
393
.env/bin/user_data/hyperopts/hyper1_1.py
Normal file
393
.env/bin/user_data/hyperopts/hyper1_1.py
Normal file
@@ -0,0 +1,393 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper1(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('tsf_long-enabled'):
|
||||
conditions.append((dataframe['close'] - dataframe['tsf_long']) > params['tsf_long-value'])
|
||||
if params.get('tsf_mid-enabled'):
|
||||
conditions.append((dataframe['tsf_mid'] - dataframe['close']) > params['tsf_mid-value'])
|
||||
if params.get('tsf_short-enabled'):
|
||||
conditions.append((dataframe['tsf_short'] - dataframe['close']) > params['tsf_short-value'])
|
||||
if params.get('angle_short-enabled'):
|
||||
conditions.append(dataframe['angle_short'] > params['angle_short-value'])
|
||||
if params.get('angle_mid-enabled'):
|
||||
conditions.append(dataframe['angle_mid'] > params['angle_mid-value'])
|
||||
if params.get('angle_long-enabled'):
|
||||
conditions.append(dataframe['angle_long'] > params['angle_long-value'])
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value'] < dataframe['correl_h_l'])
|
||||
if params.get('correl_close_last_close-enabled'):
|
||||
conditions.append(params['correl_close_last_close-value'] < dataframe['correl_close_last_close'])
|
||||
if params.get('correl_tsf_long_close-enabled'):
|
||||
conditions.append(params['correl_tsf_long_close-value'] < dataframe['correl_tsf_long_close'])
|
||||
if params.get('correl_tsf_mid_close-enabled'):
|
||||
conditions.append(params['correl_tsf_mid_close-value'] < dataframe['correl_tsf_mid_close'])
|
||||
if params.get('correl_tsf_short_close-enabled'):
|
||||
conditions.append(params['correl_tsf_short_close-value'] < dataframe['correl_tsf_short_close'])
|
||||
if params.get('correl_angle_short_close-enabled'):
|
||||
conditions.append(params['correl_angle_short_close-value'] < dataframe['correl_angle_short_close'])
|
||||
if params.get('correl_angle_mid_close-enabled'):
|
||||
conditions.append(params['correl_angle_mid_close-value'] < dataframe['correl_angle_mid_close'])
|
||||
if params.get('correl_angle_long_close-enabled'):
|
||||
conditions.append(params['correl_angle_long_close-value'] < dataframe['correl_angle_long_close'])
|
||||
if params.get('correl_hist_close-enabled'):
|
||||
conditions.append(params['correl_hist_close-value'] < dataframe['correl_hist_close'])
|
||||
if params.get('correl_mfi_close-enabled'):
|
||||
conditions.append(params['correl_mfi_close-value'] < dataframe['correl_mfi_close'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value'] < dataframe['mfi'])
|
||||
if params.get('ema-enabled'):
|
||||
conditions.append(params['ema-value'] < (dataframe['close'] - dataframe['ema']))
|
||||
if params.get('ema_bol-enabled'):
|
||||
conditions.append(params['ema_bol-value'] < (dataframe['ema'] - dataframe['middleband']))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macdhist-value'] < dataframe['macdhist'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_low':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['lowerband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'ma_cross':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['ma'], dataframe['ema']))
|
||||
if params['trigger'] == 'ema_cross':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['ema']))
|
||||
if params['trigger'] == 'mfi':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['mfi'], 25))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-100, 100, name='tsf_long-value'),
|
||||
Integer(-100, 100, name='tsf_mid-value'),
|
||||
Integer(-100, 100, name='tsf_short-value'),
|
||||
Integer(-50, 50, name='angle_short-value'),
|
||||
Integer(-50, 50, name='angle_long-value'),
|
||||
Integer(-50, 50, name='angle_mid-value'),
|
||||
Real(0, 1, name='correl_h_l-value'),
|
||||
Real(-1, 1, name='correl_close_last_close-value'),
|
||||
Real(0, 1, name='correl_tsf_long_close-value'),
|
||||
Real(-1, 1, name='correl_tsf_mid_close-value'),
|
||||
Real(-1, 1, name='correl_tsf_short_close-value'),
|
||||
Real(-1, 1, name='correl_angle_short_close-value'),
|
||||
Real(0, 1, name='correl_angle_mid_close-value'),
|
||||
Real(0, 1, name='correl_angle_long_close-value'),
|
||||
Real(-1, 1, name='correl_hist_close-value'),
|
||||
Real(-1, 1, name='correl_mfi_close-value'),
|
||||
Integer(10, 60, name='mfi-value'),
|
||||
Integer(-50, 50, name='ema-value'),
|
||||
Integer(-50, 50, name='ema_bol-value'),
|
||||
Integer(-1, 5, name='macdhist-value'),
|
||||
Categorical([True, False], name='angle_short-enabled'),
|
||||
Categorical([True, False], name='angle_long-enabled'),
|
||||
Categorical([True, False], name='angle_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_long-enabled'),
|
||||
Categorical([True, False], name='tsf_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_short-enabled'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='correl_close_last_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_mfi_close-enabled'),
|
||||
Categorical([True, False], name='correl_hist_close-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='ema-enabled'),
|
||||
Categorical([True, False], name='ema_bol-enabled'),
|
||||
Categorical(['mfi', 'macd_cross_signal', 'bol_low', 'bol_mid', 'ma_cross'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('tsf_long-enabled'):
|
||||
conditions.append((dataframe['tsf_long'] - dataframe['close']) > params['tsf_long-value_sell'])
|
||||
if params.get('tsf_mid-enabled'):
|
||||
conditions.append((dataframe['tsf_mid'] - dataframe['close']) > params['tsf_mid-value_sell'])
|
||||
if params.get('tsf_short-enabled'):
|
||||
conditions.append((dataframe['tsf_short'] - dataframe['close']) > params['tsf_short-value_sell'])
|
||||
if params.get('angle_short-enabled'):
|
||||
conditions.append(dataframe['angle_short'] > params['angle_short-value_sell'])
|
||||
if params.get('angle_mid-enabled'):
|
||||
conditions.append(dataframe['angle_mid'] > params['angle_mid-value_sell'])
|
||||
if params.get('angle_long-enabled'):
|
||||
conditions.append(dataframe['angle_long'] > params['angle_long-value_sell'])
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value_sell'] < dataframe['correl_h_l'])
|
||||
if params.get('correl_close_last_close-enabled'):
|
||||
conditions.append(params['correl_close_last_close-value_sell'] < dataframe['correl_close_last_close'])
|
||||
if params.get('correl_tsf_long_close-enabled'):
|
||||
conditions.append(params['correl_tsf_long_close-value_sell'] < dataframe['correl_tsf_long_close'])
|
||||
if params.get('correl_tsf_mid_close-enabled'):
|
||||
conditions.append(params['correl_tsf_mid_close-value_sell'] < dataframe['correl_tsf_mid_close'])
|
||||
if params.get('correl_tsf_short_close-enabled'):
|
||||
conditions.append(params['correl_tsf_short_close-value_sell'] < dataframe['correl_tsf_short_close'])
|
||||
if params.get('correl_angle_short_close-enabled'):
|
||||
conditions.append(params['correl_angle_short_close-value_sell'] < dataframe['correl_angle_short_close'])
|
||||
if params.get('correl_angle_mid_close-enabled'):
|
||||
conditions.append(params['correl_angle_mid_close-value_sell'] < dataframe['correl_angle_mid_close'])
|
||||
if params.get('correl_angle_long_close-enabled'):
|
||||
conditions.append(params['correl_angle_long_close-value_sell'] < dataframe['correl_angle_long_close'])
|
||||
if params.get('correl_hist_close-enabled'):
|
||||
conditions.append(params['correl_hist_close-value_sell'] < dataframe['correl_hist_close'])
|
||||
if params.get('correl_mfi_close-enabled'):
|
||||
conditions.append(params['correl_mfi_close-value_sell'] < dataframe['correl_mfi_close'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value_sell'] > dataframe['mfi'])
|
||||
if params.get('ema-enabled'):
|
||||
conditions.append(params['ema-value_sell'] < (dataframe['ema'] - dataframe['close']))
|
||||
if params.get('ema_bol-enabled'):
|
||||
conditions.append(params['ema_bol-value_sell'] < (dataframe['middleband'] - dataframe['ema']))
|
||||
conditions.append(params['macdhist-value_sell'] > dataframe['macdhist'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_high':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['upperband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'ma_cross':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['ema'], dataframe['middleband']))
|
||||
if params['trigger'] == 'ema_cross':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['ema']))
|
||||
if params['trigger'] == 'mfi':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['mfi'], 60))
|
||||
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-100, 100, name='tsf_long-value_sell'),
|
||||
Integer(-100, 100, name='tsf_mid-value_sell'),
|
||||
Integer(-100, 100, name='tsf_short-value_sell'),
|
||||
Integer(-50, 50, name='angle_short-value_sell'),
|
||||
Integer(-50, 50, name='angle_long-value_sell'),
|
||||
Integer(-50, 50, name='angle_mid-value_sell'),
|
||||
Real(-1, 1, name='correl_h_l-value_sell'),
|
||||
Real(-1, 1, name='correl_close_last_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_long_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_mid_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_short_close-value_sell'),
|
||||
Real(-1, 1, name='correl_angle_short_close-value_sell'),
|
||||
Real(-1, 1, name='correl_angle_mid_close-value_sell'),
|
||||
Real(-1, 1, name='correl_angle_long_close-value_sell'),
|
||||
Real(-1, 1, name='correl_hist_close-value_sell'),
|
||||
Real(-1, 1, name='correl_mfi_close-value_sell'),
|
||||
Integer(40, 100, name='mfi-value_sell'),
|
||||
Integer(-5, 50, name='ema-value_sell'),
|
||||
Integer(-5, 50, name='ema_bol-value_sell'),
|
||||
Integer(-10, 20, name='macdhist-value_sell'),
|
||||
Categorical([True, False], name='angle_short-enabled'),
|
||||
Categorical([True, False], name='angle_long-enabled'),
|
||||
Categorical([True, False], name='angle_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_long-enabled'),
|
||||
Categorical([True, False], name='tsf_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_short-enabled'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='correl_close_last_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_mfi_close-enabled'),
|
||||
Categorical([True, False], name='correl_hist_close-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='ema-enabled'),
|
||||
Categorical([True, False], name='ema_bol-enabled'),
|
||||
Categorical(['mfi', 'macd_cross_signal', 'bol_high', 'bol_mid', 'ma_cross'], name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 120, name='roi_t1'),
|
||||
Integer(10, 60, name='roi_t2'),
|
||||
Integer(10, 40, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
176
.env/bin/user_data/hyperopts/hyper2.py
Normal file
176
.env/bin/user_data/hyperopts/hyper2.py
Normal file
@@ -0,0 +1,176 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper2(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('uo-enabled'):
|
||||
conditions.append(dataframe['uo'] > params['uo_h'])
|
||||
if params.get('angle-enabled'):
|
||||
conditions.append(dataframe['angle'] > params['angle_h'])
|
||||
if params.get('sar-enabled'):
|
||||
conditions.append(params['sar_ratio'] < (dataframe['sar'] - dataframe['close']))
|
||||
conditions.append(params['sar_shift'] > (dataframe['sar'] - dataframe['sar'].shift(3)))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macd_value'] > dataframe['macd'])
|
||||
conditions.append(params['macdhist_value'] > dataframe['macdhist'])
|
||||
conditions.append(params['macdhist_shift'] < (dataframe['macdhist'] - dataframe['macdhist'].shift(3)))
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['sar']
|
||||
))
|
||||
if params['trigger'] == 'angle':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['angle'], 0
|
||||
))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
conditions.append(dataframe['angle'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(0, 100, name='uo_h'),
|
||||
Real(-1, 1, name='angle_h'),
|
||||
Real(0, 1, name='sar_ratio'),
|
||||
Real(0, 1, name='sar_shift'),
|
||||
Real(-1, 1, name='macd_value'),
|
||||
Real(-1, 1, name='macdhist_value'),
|
||||
Real(-1, 1, name='macdhist_shift'),
|
||||
Categorical([True, False], name='angle-enabled'),
|
||||
Categorical([True, False], name='sar-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical(['sar'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('sell-uo-enabled'):
|
||||
conditions.append(dataframe['uo'] > params['uo_l_s'])
|
||||
if params.get('angle-enabled'):
|
||||
conditions.append(params['angle_h_s'] < dataframe['angle'])
|
||||
if params.get('sar-enabled'):
|
||||
conditions.append(params['sar_ratio_s'] < (dataframe['sar'] - dataframe['close']))
|
||||
conditions.append(params['sar_shift_s'] < (dataframe['sar'] - dataframe['sar'].shift(3)))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macd_value_s'] > dataframe['macd'])
|
||||
conditions.append(params['macdhist_value_s'] > dataframe['macdhist'])
|
||||
conditions.append(params['macdhist_shift_s'] > (dataframe['macdhist'] - dataframe['macdhist'].shift(3)))
|
||||
|
||||
# TRIGGERS
|
||||
if 'sell-trigger' in params:
|
||||
if params['sell-trigger'] == 'sell-sar_reversal':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['sar'], dataframe['close']
|
||||
))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(0, 100, name='uo_l_s'),
|
||||
Real(-1, 1, name='angle_h_s'),
|
||||
Real(0, 1, name='sar_ratio_s'),
|
||||
Real(0, 1, name='sar_shift_s'),
|
||||
Real(-1, 1, name='macd_value_s'),
|
||||
Real(-1, 1, name='macdhist_value_s'),
|
||||
Real(-1, 1, name='macdhist_shift_s'),
|
||||
Categorical([True, False], name='sell-uo-enabled'),
|
||||
Categorical([True, False], name='sell-angle-enabled'),
|
||||
Categorical([True, False], name='sell-sar-enabled'),
|
||||
Categorical([True, False], name='sell-macd-enabled'),
|
||||
Categorical(['sell-angle', 'sell-macd_cross_signal', 'sell-sar_reversal'], name='trigger')
|
||||
]
|
||||
388
.env/bin/user_data/hyperopts/hyper_adausdt.py
Normal file
388
.env/bin/user_data/hyperopts/hyper_adausdt.py
Normal file
@@ -0,0 +1,388 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper_adausdt(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('tsf_long-enabled'):
|
||||
conditions.append((dataframe['close'] - dataframe['tsf_long']) < params['tsf_long-value'])
|
||||
if params.get('tsf_mid-enabled'):
|
||||
conditions.append((dataframe['close'] - dataframe['tsf_mid']) < params['tsf_mid-value'])
|
||||
if params.get('tsf_short-enabled'):
|
||||
conditions.append((dataframe['close'] - dataframe['tsf_short']) < params['tsf_short-value'])
|
||||
if params.get('angle_short-enabled'):
|
||||
conditions.append(dataframe['angle_short'] > params['angle_short-value'])
|
||||
if params.get('angle_mid-enabled'):
|
||||
conditions.append(dataframe['angle_mid'] > params['angle_mid-value'])
|
||||
if params.get('angle_long-enabled'):
|
||||
conditions.append(dataframe['angle_long'] > params['angle_long-value'])
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value'] < dataframe['correl_h_l'])
|
||||
if params.get('correl_close_last_close-enabled'):
|
||||
conditions.append(params['correl_close_last_close-value'] < dataframe['correl_close_last_close'])
|
||||
if params.get('correl_tsf_long_close-enabled'):
|
||||
conditions.append(params['correl_tsf_long_close-value'] < dataframe['correl_tsf_long_close'])
|
||||
if params.get('correl_tsf_mid_close-enabled'):
|
||||
conditions.append(params['correl_tsf_mid_close-value'] < dataframe['correl_tsf_mid_close'])
|
||||
if params.get('correl_tsf_short_close-enabled'):
|
||||
conditions.append(params['correl_tsf_short_close-value'] < dataframe['correl_tsf_short_close'])
|
||||
if params.get('correl_angle_short_close-enabled'):
|
||||
conditions.append(params['correl_angle_short_close-value'] < dataframe['correl_angle_short_close'])
|
||||
if params.get('correl_angle_mid_close-enabled'):
|
||||
conditions.append(params['correl_angle_mid_close-value'] < dataframe['correl_angle_mid_close'])
|
||||
if params.get('correl_angle_long_close-enabled'):
|
||||
conditions.append(params['correl_angle_long_close-value'] < dataframe['correl_angle_long_close'])
|
||||
if params.get('correl_hist_close-enabled'):
|
||||
conditions.append(params['correl_hist_close-value'] < dataframe['correl_hist_close'])
|
||||
if params.get('correl_mfi_close-enabled'):
|
||||
conditions.append(params['correl_mfi_close-value'] < dataframe['correl_mfi_close'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value'] < dataframe['mfi'])
|
||||
if params.get('ema-enabled'):
|
||||
conditions.append(params['ema-value'] < (dataframe['close'] - dataframe['ema']))
|
||||
if params.get('ema_bol-enabled'):
|
||||
conditions.append(params['ema_bol-value'] < (dataframe['ema'] - dataframe['middleband']))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macdhist-value'] < dataframe['macdhist'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_low':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['lowerband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'mfi':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['mfi'], 25))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['sar'], dataframe['close']))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(0.019, 0.7, name='tsf_long-value'),
|
||||
Real(0.019, 0.7, name='tsf_mid-value'),
|
||||
Real(0.17, 0.7, name='tsf_short-value'),
|
||||
Real(-0.26, 0.23, name='angle_short-value'),
|
||||
Real(-0.018, 0.023, name='angle_long-value'),
|
||||
Real(-0.026, 0.028, name='angle_mid-value'),
|
||||
Real(0, 1, name='correl_h_l-value'),
|
||||
Real(-1, 1, name='correl_close_last_close-value'),
|
||||
Real(0, 1, name='correl_tsf_long_close-value'),
|
||||
Real(-1, 1, name='correl_tsf_mid_close-value'),
|
||||
Real(-1, 1, name='correl_tsf_short_close-value'),
|
||||
Real(-1, 1, name='correl_angle_short_close-value'),
|
||||
Real(0, 1, name='correl_angle_mid_close-value'),
|
||||
Real(0, 1, name='correl_angle_long_close-value'),
|
||||
Real(-1, 1, name='correl_hist_close-value'),
|
||||
Real(-1, 1, name='correl_mfi_close-value'),
|
||||
Integer(10, 60, name='mfi-value'),
|
||||
Real(0.18, 0.7, name='ema-value'),
|
||||
Real(-0.018, 0.015, name='ema_bol-value'),
|
||||
Real(-0.0042, 0.003, name='macdhist-value'),
|
||||
Categorical([True, False], name='angle_short-enabled'),
|
||||
Categorical([True, False], name='angle_long-enabled'),
|
||||
Categorical([True, False], name='angle_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_long-enabled'),
|
||||
Categorical([True, False], name='tsf_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_short-enabled'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='correl_close_last_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_mfi_close-enabled'),
|
||||
Categorical([True, False], name='correl_hist_close-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='ema-enabled'),
|
||||
Categorical([True, False], name='ema_bol-enabled'),
|
||||
Categorical(['sar', 'mfi', 'macd_cross_signal', 'bol_low', 'bol_mid'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('tsf_long-enabled'):
|
||||
conditions.append((dataframe['tsf_long'] - dataframe['close']) > params['tsf_long-value_sell'])
|
||||
if params.get('tsf_mid-enabled'):
|
||||
conditions.append((dataframe['tsf_mid'] - dataframe['close']) > params['tsf_mid-value_sell'])
|
||||
if params.get('tsf_short-enabled'):
|
||||
conditions.append((dataframe['tsf_short'] - dataframe['close']) > params['tsf_short-value_sell'])
|
||||
if params.get('angle_short-enabled'):
|
||||
conditions.append(dataframe['angle_short'] > params['angle_short-value_sell'])
|
||||
if params.get('angle_mid-enabled'):
|
||||
conditions.append(dataframe['angle_mid'] > params['angle_mid-value_sell'])
|
||||
if params.get('angle_long-enabled'):
|
||||
conditions.append(dataframe['angle_long'] > params['angle_long-value_sell'])
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value_sell'] < dataframe['correl_h_l'])
|
||||
if params.get('correl_close_last_close-enabled'):
|
||||
conditions.append(params['correl_close_last_close-value_sell'] < dataframe['correl_close_last_close'])
|
||||
if params.get('correl_tsf_long_close-enabled'):
|
||||
conditions.append(params['correl_tsf_long_close-value_sell'] < dataframe['correl_tsf_long_close'])
|
||||
if params.get('correl_tsf_mid_close-enabled'):
|
||||
conditions.append(params['correl_tsf_mid_close-value_sell'] < dataframe['correl_tsf_mid_close'])
|
||||
if params.get('correl_tsf_short_close-enabled'):
|
||||
conditions.append(params['correl_tsf_short_close-value_sell'] < dataframe['correl_tsf_short_close'])
|
||||
if params.get('correl_angle_short_close-enabled'):
|
||||
conditions.append(params['correl_angle_short_close-value_sell'] < dataframe['correl_angle_short_close'])
|
||||
if params.get('correl_angle_mid_close-enabled'):
|
||||
conditions.append(params['correl_angle_mid_close-value_sell'] < dataframe['correl_angle_mid_close'])
|
||||
if params.get('correl_angle_long_close-enabled'):
|
||||
conditions.append(params['correl_angle_long_close-value_sell'] < dataframe['correl_angle_long_close'])
|
||||
if params.get('correl_hist_close-enabled'):
|
||||
conditions.append(params['correl_hist_close-value_sell'] < dataframe['correl_hist_close'])
|
||||
if params.get('correl_mfi_close-enabled'):
|
||||
conditions.append(params['correl_mfi_close-value_sell'] < dataframe['correl_mfi_close'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value_sell'] > dataframe['mfi'])
|
||||
if params.get('ema-enabled'):
|
||||
conditions.append(params['ema-value_sell'] < (dataframe['ema'] - dataframe['close']))
|
||||
if params.get('sar-enabled'):
|
||||
conditions.append(params['sar-value_sell'] < (dataframe['close'] - dataframe['sar']))
|
||||
if params.get('ema_bol-enabled'):
|
||||
conditions.append(params['ema_bol-value_sell'] < (dataframe['middleband'] - dataframe['ema']))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macdhist-value_sell'] > dataframe['macdhist'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_high':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['upperband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['sar'], dataframe['close']))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(0.019, 0.7, name='tsf_long-value_sell'),
|
||||
Real(0.019, 0.7, name='tsf_mid-value_sell'),
|
||||
Real(0.17, 0.7, name='tsf_short-value_sell'),
|
||||
Real(-0.26, 0.23, name='angle_short-value_sell'),
|
||||
Real(-0.018, 0.023, name='angle_long-value_sell'),
|
||||
Real(-0.026, 0.028, name='angle_mid-value_sell'),
|
||||
Real(0, 1, name='correl_h_l-value_sell'),
|
||||
Real(-1, 1, name='correl_close_last_close-value_sell'),
|
||||
Real(0, 1, name='correl_tsf_long_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_mid_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_short_close-value_sell'),
|
||||
Real(-1, 1, name='correl_angle_short_close-value_sell'),
|
||||
Real(0, 1, name='correl_angle_mid_close-value_sell'),
|
||||
Real(0, 1, name='correl_angle_long_close-value_sell'),
|
||||
Real(-1, 1, name='correl_hist_close-value_sell'),
|
||||
Real(-1, 1, name='correl_mfi_close-value_sell'),
|
||||
Real(10, 60, name='mfi-value_sell'),
|
||||
Real(0.018, 0.7, name='ema-value_sell'),
|
||||
Real(0.017, 0.7, name='sar-value_sell'),
|
||||
Real(-0.018, 0.015, name='ema_bol-value_sell'),
|
||||
Real(-0.0042, 0.003, name='macdhist-value_sell'),
|
||||
Categorical([True, False], name='angle_short-enabled'),
|
||||
Categorical([True, False], name='angle_long-enabled'),
|
||||
Categorical([True, False], name='angle_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_long-enabled'),
|
||||
Categorical([True, False], name='tsf_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_short-enabled'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='correl_close_last_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_mfi_close-enabled'),
|
||||
Categorical([True, False], name='correl_hist_close-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='ema-enabled'),
|
||||
Categorical([True, False], name='sar-enabled'),
|
||||
Categorical([True, False], name='ema_bol-enabled'),
|
||||
Categorical(['sar', 'macd_cross_signal', 'bol_low', 'bol_mid'], name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 120, name='roi_t1'),
|
||||
Integer(10, 60, name='roi_t2'),
|
||||
Integer(10, 40, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
256
.env/bin/user_data/hyperopts/hyper_adausdt2.py
Normal file
256
.env/bin/user_data/hyperopts/hyper_adausdt2.py
Normal file
@@ -0,0 +1,256 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper_adausdt2(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value'] < dataframe['correl_h_l'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value'] < dataframe['mfi'])
|
||||
if params.get('sar-enabled'):
|
||||
conditions.append(params['sar-value'] < (dataframe['close'] - dataframe['sar']))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macdhist-value'] < dataframe['macdhist'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_low':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['lowerband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'mfi':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['mfi'], 25))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['sar'], dataframe['close']))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(-1, 1, name='correl_h_l-value'),
|
||||
Integer(10, 60, name='mfi-value'),
|
||||
Integer(-112, 158, name='sar-value'),
|
||||
Real(-0.0042, 0.003, name='macdhist-value'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='sar-enabled'),
|
||||
Categorical(['sar', 'mfi', 'macd_cross_signal', 'bol_low', 'bol_mid'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value_sell'] < dataframe['correl_h_l'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value_sell'] > dataframe['mfi'])
|
||||
if params.get('sar-enabled'):
|
||||
conditions.append(params['sar-value_sell'] < (dataframe['close'] - dataframe['sar']))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macdhist-value_sell'] > dataframe['macdhist'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_high':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['upperband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['sar'], dataframe['close']))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(0, 1, name='correl_h_l-value_sell'),
|
||||
Real(10, 60, name='mfi-value_sell'),
|
||||
Real(0.017, 0.7, name='sar-value_sell'),
|
||||
Real(-0.0042, 0.003, name='macdhist-value_sell'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='sar-enabled'),
|
||||
Categorical(['sar', 'macd_cross_signal', 'bol_low', 'bol_mid'], name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 120, name='roi_t1'),
|
||||
Integer(10, 60, name='roi_t2'),
|
||||
Integer(10, 40, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
356
.env/bin/user_data/hyperopts/hyper_adausdt3.py
Normal file
356
.env/bin/user_data/hyperopts/hyper_adausdt3.py
Normal file
@@ -0,0 +1,356 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper_adausdt3(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('aroon-enabled'):
|
||||
conditions.append((dataframe['aroon_up'] - dataframe['aroon_down']) > params['aroon-value'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(dataframe['rsi'] > params['rsi-value'])
|
||||
if params.get('ul-enabled'):
|
||||
conditions.append(dataframe['ul'] > params['ul-value'])
|
||||
if params.get('stoch_ratio-enabled'):
|
||||
conditions.append((dataframe['slowk'] - dataframe['slowd']) > params['stoch_ratio-value'])
|
||||
if params.get('stoch-enabled'):
|
||||
conditions.append(dataframe['slowk'] > params['stoch-value'])
|
||||
if params.get('ht_phase-enabled'):
|
||||
conditions.append(dataframe['ht_phase'] < params['ht_phase-value'])
|
||||
if params.get('inphase-enabled'):
|
||||
conditions.append(dataframe['inphase'] > params['inphase-value'])
|
||||
if params.get('quadrature-enabled'):
|
||||
conditions.append(dataframe['quadrature'] > params['quadrature-value'])
|
||||
if params.get('ht_trendmode-enabled'):
|
||||
conditions.append(dataframe['ht_trendmode'] > params['ht_trendmode-value'])
|
||||
if params.get('correl_sine_trend-enabled'):
|
||||
conditions.append(params['correl_sine_trend-value'] < dataframe['correl_sine_trend'])
|
||||
if params.get('ht_trendline-enabled'):
|
||||
conditions.append(params['ht_trendline-value'] < (dataframe['ht_trendline'] - dataframe['close']))
|
||||
if params.get('ht_sine-enabled'):
|
||||
conditions.append(params['ht_sine-value'] < (dataframe['ht_sine'] - dataframe['leadsine']))
|
||||
if params.get('correl_sine_trend-enabled'):
|
||||
conditions.append(params['correl_sine_trend-value'] < dataframe['correl_sine_trend'])
|
||||
if params.get('correl_ht_sine_trend-enabled'):
|
||||
conditions.append(params['correl_ht_sine_trend-value'] < dataframe['correl_ht_sine_trend'])
|
||||
if params.get('correl_ht_sine_close-enabled'):
|
||||
conditions.append(params['correl_ht_sine_close-value'] < dataframe['correl_ht_sine_close'])
|
||||
if params.get('cci-enabled'):
|
||||
conditions.append(params['cci-value'] < dataframe['cci'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'phasor':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['quadrature'], dataframe['inphase']
|
||||
))
|
||||
if params['trigger'] == 'ht_trendmode':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['ht_trendmode'], 0
|
||||
))
|
||||
if params['trigger'] == 'ht_sine':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['leadsine'], dataframe['ht_sine']
|
||||
))
|
||||
if params['trigger'] == 'aroon_osc':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['aroonosc'], 0))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-100, 100, name='aroon-value'),
|
||||
Real(2.4, 100, name='rsi-value'),
|
||||
Real(0, 100, name='ul-value'),
|
||||
Real(-42, 42, name='stoch_ratio-value'),
|
||||
Integer(0, 100, name='stoch-value'),
|
||||
Real(-0.025, 0.0238, name='inphase-value'),
|
||||
Real(-0.0741, 0.047, name='quadrature-value'),
|
||||
Integer(0, 1, name='ht_trendmode-value'),
|
||||
Real(-1, 1, name='correl_sine_trend-value'),
|
||||
Real(-1, 1, name='ht_trendline-value'),
|
||||
Real(-0.76, 0.76, name='ht_sine-value'),
|
||||
Real(-1, 1, name='correl_sine_trend-value'),
|
||||
Real(-1, 1, name='correl_ht_sine_trend-value'),
|
||||
Real(-1, 1, name='correl_ht_sine_close-value'),
|
||||
Integer(-1000, 1000, name='cci-value'),
|
||||
Integer(-44, 310, name='ht_phase-value'),
|
||||
|
||||
Categorical([True, False], name='aroon-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical([True, False], name='ul-enabled'),
|
||||
Categorical([True, False], name='stoch_ratio-enabled'),
|
||||
Categorical([True, False], name='stoch-enabled'),
|
||||
Categorical([True, False], name='inphase-enabled'),
|
||||
Categorical([True, False], name='ht_phase-enabled'),
|
||||
Categorical([True, False], name='correl_sine_trend-enabled'),
|
||||
Categorical([True, False], name='quadrature-enabled'),
|
||||
Categorical([True, False], name='ht_trendline-enabled'),
|
||||
Categorical([True, False], name='correl_sine_trend-enabled'),
|
||||
Categorical([True, False], name='correl_ht_sine_trend-enabled'),
|
||||
Categorical([True, False], name='cci-enabled'),
|
||||
Categorical(['ht_sine', 'phasor', 'macd_cross_signal', 'aroon_osc', 'ht_trendmode'],
|
||||
name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('aroon-enabled'):
|
||||
conditions.append((dataframe['aroon_down'] - dataframe['aroon_up']) > params['aroon-value_sell'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(dataframe['rsi'] < params['rsi-value_sell'])
|
||||
if params.get('ul-enabled'):
|
||||
conditions.append(dataframe['ul'] < params['ul-value_sell'])
|
||||
if params.get('stoch_ratio-enabled'):
|
||||
conditions.append((dataframe['slowd'] - dataframe['slowk']) > params['stoch_ratio-value_sell'])
|
||||
if params.get('stoch-enabled'):
|
||||
conditions.append(dataframe['slowk'] < params['stoch-value_sell'])
|
||||
if params.get('ht_phase-enabled'):
|
||||
conditions.append(dataframe['ht_phase'] < params['ht_phase-value_sell'])
|
||||
if params.get('inphase-enabled'):
|
||||
conditions.append(dataframe['inphase'] > params['inphase-value_sell'])
|
||||
if params.get('quadrature-enabled'):
|
||||
conditions.append(dataframe['quadrature'] > params['quadrature-value_sell'])
|
||||
if params.get('ht_trendmode-enabled'):
|
||||
conditions.append(dataframe['ht_trendmode'] < params['ht_trendmode-value'])
|
||||
if params.get('correl_sine_trend-enabled'):
|
||||
conditions.append(params['correl_sine_trend-value_sell'] < dataframe['correl_sine_trend'])
|
||||
if params.get('ht_trendline-enabled'):
|
||||
conditions.append(params['ht_trendline-value_sell'] > (dataframe['close'] - dataframe['ht_trendline']))
|
||||
if params.get('ht_sine-enabled'):
|
||||
conditions.append(params['ht_sine-value_sell'] < (dataframe['ht_trendline'] - dataframe['ht_sine']))
|
||||
if params.get('correl_sine_trend-enabled'):
|
||||
conditions.append(params['correl_sine_trend-value_sell'] < dataframe['correl_sine_trend'])
|
||||
if params.get('correl_ht_sine_trend-enabled'):
|
||||
conditions.append(params['correl_ht_sine_trend-value_sell'] < dataframe['correl_ht_sine_trend'])
|
||||
if params.get('correl_ht_sine_close-enabled'):
|
||||
conditions.append(params['correl_ht_sine_close-value_sell'] < dataframe['correl_ht_sine_close'])
|
||||
if params.get('cci-enabled'):
|
||||
conditions.append(params['cci-value'] < dataframe['cci'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'phasor':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['quadrature'], dataframe['inphase']
|
||||
))
|
||||
if params['trigger'] == 'ht_trendmode':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['ht_trendmode'], 1
|
||||
))
|
||||
if params['trigger'] == 'ht_sine':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['leadsine'], dataframe['ht_sine']
|
||||
))
|
||||
if params['trigger'] == 'aroon_osc':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['aroonosc'], 0))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-100, 100, name='aroon-value_sell'),
|
||||
Real(2.4, 100, name='rsi-value_sell'),
|
||||
Real(0, 100, name='ul-value_sell'),
|
||||
Real(-42, 42, name='stoch_ratio-value_sell'),
|
||||
Integer(0, 100, name='stoch-value_sell'),
|
||||
Real(-0.025, 0.0238, name='inphase-value_sell'),
|
||||
Real(-0.0741, 0.047, name='quadrature-value_sell'),
|
||||
Real(-1, 1, name='correl_sine_trend-value_sell'),
|
||||
Real(-1, 1, name='ht_trendline-value_sell'),
|
||||
Real(-0.76, 0.76, name='ht_sine-value_sell'),
|
||||
Real(-1, 1, name='correl_sine_trend-value_sell'),
|
||||
Real(-1, 1, name='correl_ht_sine_trend-value_sell'),
|
||||
Real(-1, 1, name='correl_ht_sine_close-value_sell'),
|
||||
Integer(-1000, 1000, name='cci-value_sell'),
|
||||
Integer(-44, 310, name='ht_phase-value_sell'),
|
||||
Integer(0, 1, name='ht_trendmode-value_sell'),
|
||||
|
||||
Categorical([True, False], name='aroon-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical([True, False], name='ul-enabled'),
|
||||
Categorical([True, False], name='stoch_ratio-enabled'),
|
||||
Categorical([True, False], name='stoch-enabled'),
|
||||
Categorical([True, False], name='inphase-enabled'),
|
||||
Categorical([True, False], name='ht_phase-enabled'),
|
||||
Categorical([True, False], name='correl_sine_trend-enabled'),
|
||||
Categorical([True, False], name='quadrature-enabled'),
|
||||
Categorical([True, False], name='ht_trendline-enabled'),
|
||||
Categorical([True, False], name='correl_sine_trend-enabled'),
|
||||
Categorical([True, False], name='correl_ht_sine_trend-enabled'),
|
||||
Categorical([True, False], name='cci-enabled'),
|
||||
Categorical(
|
||||
['ht_sine', 'aroon_osc', 'ht_trendmode', 'phasor', 'macd_cross_signal'],
|
||||
name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 120, name='roi_t1'),
|
||||
Integer(10, 60, name='roi_t2'),
|
||||
Integer(10, 40, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
402
.env/bin/user_data/hyperopts/hyper_dogeusdt.py
Normal file
402
.env/bin/user_data/hyperopts/hyper_dogeusdt.py
Normal file
@@ -0,0 +1,402 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper_dogeusdt(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('tsf_long-enabled'):
|
||||
conditions.append((dataframe['close'] - dataframe['tsf_long']) < params['tsf_long-value'])
|
||||
if params.get('tsf_mid-enabled'):
|
||||
conditions.append((dataframe['close'] - dataframe['tsf_mid']) < params['tsf_mid-value'])
|
||||
if params.get('tsf_short-enabled'):
|
||||
conditions.append((dataframe['close'] - dataframe['tsf_short']) < params['tsf_short-value'])
|
||||
if params.get('angle_short-enabled'):
|
||||
conditions.append(dataframe['angle_short'] > params['angle_short-value'])
|
||||
if params.get('angle_mid-enabled'):
|
||||
conditions.append(dataframe['angle_mid'] > params['angle_mid-value'])
|
||||
if params.get('angle_long-enabled'):
|
||||
conditions.append(dataframe['angle_long'] > params['angle_long-value'])
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value'] < dataframe['correl_h_l'])
|
||||
if params.get('correl_close_last_close-enabled'):
|
||||
conditions.append(params['correl_close_last_close-value'] < dataframe['correl_close_last_close'])
|
||||
if params.get('correl_tsf_long_close-enabled'):
|
||||
conditions.append(params['correl_tsf_long_close-value'] < dataframe['correl_tsf_long_close'])
|
||||
if params.get('correl_tsf_mid_close-enabled'):
|
||||
conditions.append(params['correl_tsf_mid_close-value'] < dataframe['correl_tsf_mid_close'])
|
||||
if params.get('correl_tsf_short_close-enabled'):
|
||||
conditions.append(params['correl_tsf_short_close-value'] < dataframe['correl_tsf_short_close'])
|
||||
if params.get('correl_angle_short_close-enabled'):
|
||||
conditions.append(params['correl_angle_short_close-value'] < dataframe['correl_angle_short_close'])
|
||||
if params.get('correl_angle_mid_close-enabled'):
|
||||
conditions.append(params['correl_angle_mid_close-value'] < dataframe['correl_angle_mid_close'])
|
||||
if params.get('correl_angle_long_close-enabled'):
|
||||
conditions.append(params['correl_angle_long_close-value'] < dataframe['correl_angle_long_close'])
|
||||
if params.get('correl_hist_close-enabled'):
|
||||
conditions.append(params['correl_hist_close-value'] < dataframe['correl_hist_close'])
|
||||
if params.get('correl_mfi_close-enabled'):
|
||||
conditions.append(params['correl_mfi_close-value'] < dataframe['correl_mfi_close'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value'] < dataframe['mfi'])
|
||||
if params.get('ema-enabled'):
|
||||
conditions.append(params['ema-value'] < (dataframe['close'] - dataframe['ema']))
|
||||
if params.get('ema_bol-enabled'):
|
||||
conditions.append(params['ema_bol-value'] < (dataframe['ema'] - dataframe['middleband']))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macdhist-value'] < dataframe['macdhist'])
|
||||
if params.get('sar-enabled'):
|
||||
conditions.append(params['sar-value_sell'] < (dataframe['close'] - dataframe['sar']))
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_low':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['lowerband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'ma_cross':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['ma'], dataframe['ema']))
|
||||
if params['trigger'] == 'ema_cross':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['close'], dataframe['ema']))
|
||||
if params['trigger'] == 'mfi':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['mfi'], 25))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(-0.03, 0.027, name='tsf_long-value'),
|
||||
Real(-0.023, 0.026, name='tsf_mid-value'),
|
||||
Real(-0.0102, 0.009, name='tsf_short-value'),
|
||||
Real(-0.136, 0.143, name='angle_short-value'),
|
||||
Real(-0.0069, 0.009, name='angle_long-value'),
|
||||
Real(-0.0154, 0.02, name='angle_mid-value'),
|
||||
Real(0, 1, name='correl_h_l-value'),
|
||||
Real(-1, 1, name='correl_close_last_close-value'),
|
||||
Real(0, 1, name='correl_tsf_long_close-value'),
|
||||
Real(-1, 1, name='correl_tsf_mid_close-value'),
|
||||
Real(-1, 1, name='correl_tsf_short_close-value'),
|
||||
Real(-1, 1, name='correl_angle_short_close-value'),
|
||||
Real(0, 1, name='correl_angle_mid_close-value'),
|
||||
Real(0, 1, name='correl_angle_long_close-value'),
|
||||
Real(-1, 1, name='correl_hist_close-value'),
|
||||
Real(-1, 1, name='correl_mfi_close-value'),
|
||||
Integer(10, 60, name='mfi-value'),
|
||||
Real(0.0012, 0.08, name='ema-value'),
|
||||
Real(-0.0087, 0.009, name='ema_bol-value'),
|
||||
Real(-0.02, 0.02, name='sar-value'),
|
||||
Real(-0.0021, 0.00163, name='macdhist-value'),
|
||||
Categorical([True, False], name='angle_short-enabled'),
|
||||
Categorical([True, False], name='angle_long-enabled'),
|
||||
Categorical([True, False], name='angle_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_long-enabled'),
|
||||
Categorical([True, False], name='tsf_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_short-enabled'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='correl_close_last_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_mfi_close-enabled'),
|
||||
Categorical([True, False], name='correl_hist_close-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='ema-enabled'),
|
||||
Categorical([True, False], name='sar-enabled'),
|
||||
Categorical([True, False], name='ema_bol-enabled'),
|
||||
Categorical(['mfi', 'macd_cross_signal', 'bol_low', 'bol_mid', 'ma_cross'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('tsf_long-enabled'):
|
||||
conditions.append((dataframe['tsf_long'] - dataframe['close']) > params['tsf_long-value_sell'])
|
||||
if params.get('tsf_mid-enabled'):
|
||||
conditions.append((dataframe['tsf_mid'] - dataframe['close']) > params['tsf_mid-value_sell'])
|
||||
if params.get('tsf_short-enabled'):
|
||||
conditions.append((dataframe['tsf_short'] - dataframe['close']) > params['tsf_short-value_sell'])
|
||||
if params.get('angle_short-enabled'):
|
||||
conditions.append(dataframe['angle_short'] > params['angle_short-value_sell'])
|
||||
if params.get('angle_mid-enabled'):
|
||||
conditions.append(dataframe['angle_mid'] > params['angle_mid-value_sell'])
|
||||
if params.get('angle_long-enabled'):
|
||||
conditions.append(dataframe['angle_long'] > params['angle_long-value_sell'])
|
||||
if params.get('correl_h_l-enabled'):
|
||||
conditions.append(params['correl_h_l-value_sell'] < dataframe['correl_h_l'])
|
||||
if params.get('correl_close_last_close-enabled'):
|
||||
conditions.append(params['correl_close_last_close-value_sell'] < dataframe['correl_close_last_close'])
|
||||
if params.get('correl_tsf_long_close-enabled'):
|
||||
conditions.append(params['correl_tsf_long_close-value_sell'] < dataframe['correl_tsf_long_close'])
|
||||
if params.get('correl_tsf_mid_close-enabled'):
|
||||
conditions.append(params['correl_tsf_mid_close-value_sell'] < dataframe['correl_tsf_mid_close'])
|
||||
if params.get('correl_tsf_short_close-enabled'):
|
||||
conditions.append(params['correl_tsf_short_close-value_sell'] < dataframe['correl_tsf_short_close'])
|
||||
if params.get('correl_angle_short_close-enabled'):
|
||||
conditions.append(params['correl_angle_short_close-value_sell'] < dataframe['correl_angle_short_close'])
|
||||
if params.get('correl_angle_mid_close-enabled'):
|
||||
conditions.append(params['correl_angle_mid_close-value_sell'] < dataframe['correl_angle_mid_close'])
|
||||
if params.get('correl_angle_long_close-enabled'):
|
||||
conditions.append(params['correl_angle_long_close-value_sell'] < dataframe['correl_angle_long_close'])
|
||||
if params.get('correl_hist_close-enabled'):
|
||||
conditions.append(params['correl_hist_close-value_sell'] < dataframe['correl_hist_close'])
|
||||
if params.get('correl_mfi_close-enabled'):
|
||||
conditions.append(params['correl_mfi_close-value_sell'] < dataframe['correl_mfi_close'])
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append(params['mfi-value_sell'] > dataframe['mfi'])
|
||||
if params.get('ema-enabled'):
|
||||
conditions.append(params['ema-value_sell'] < (dataframe['ema'] - dataframe['close']))
|
||||
if params.get('sar-enabled'):
|
||||
conditions.append(params['sar-value_sell'] < (dataframe['close'] - dataframe['sar']))
|
||||
if params.get('ema_bol-enabled'):
|
||||
conditions.append(params['ema_bol-value_sell'] < (dataframe['middleband'] - dataframe['ema']))
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append(params['macdhist-value_sell'] > dataframe['macdhist'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'bol_high':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['upperband']
|
||||
))
|
||||
if params['trigger'] == 'bol_mid':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['middleband']
|
||||
))
|
||||
if params['trigger'] == 'ma_cross':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['ema'], dataframe['middleband']))
|
||||
if params['trigger'] == 'ema_cross':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['close'], dataframe['ema']))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['sar'], dataframe['close']))
|
||||
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(-0.03, 0.027, name='tsf_long-value_sell'),
|
||||
Real(-0.023, 0.026, name='tsf_mid-value_sell'),
|
||||
Real(-0.0102, 0.009, name='tsf_short-value_sell'),
|
||||
Real(-0.136, 0.143, name='angle_short-value_sell'),
|
||||
Real(-0.0069, 0.009, name='angle_long-value_sell'),
|
||||
Real(-0.0154, 0.02, name='angle_mid-value_sell'),
|
||||
Real(0, 1, name='correl_h_l-value_sell'),
|
||||
Real(-1, 1, name='correl_close_last_close-value_sell'),
|
||||
Real(0, 1, name='correl_tsf_long_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_mid_close-value_sell'),
|
||||
Real(-1, 1, name='correl_tsf_short_close-value_sell'),
|
||||
Real(-1, 1, name='correl_angle_short_close-value_sell'),
|
||||
Real(0, 1, name='correl_angle_mid_close-value_sell'),
|
||||
Real(0, 1, name='correl_angle_long_close-value_sell'),
|
||||
Real(-1, 1, name='correl_hist_close-value_sell'),
|
||||
Real(-1, 1, name='correl_mfi_close-value_sell'),
|
||||
Integer(10, 60, name='mfi-value_sell'),
|
||||
Real(0.0012, 0.08, name='ema-value_sell'),
|
||||
Real(-0.0087, 0.009, name='ema_bol-value_sell'),
|
||||
Real(-0.02, 0.02, name='sar-value_sell'),
|
||||
Real(-0.0021, 0.00163, name='macdhist-value_sell'),
|
||||
Categorical([True, False], name='angle_short-enabled'),
|
||||
Categorical([True, False], name='angle_long-enabled'),
|
||||
Categorical([True, False], name='angle_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_long-enabled'),
|
||||
Categorical([True, False], name='tsf_mid-enabled'),
|
||||
Categorical([True, False], name='tsf_short-enabled'),
|
||||
Categorical([True, False], name='correl_h_l-enabled'),
|
||||
Categorical([True, False], name='correl_close_last_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_tsf_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_short_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_mid_close-enabled'),
|
||||
Categorical([True, False], name='correl_angle_long_close-enabled'),
|
||||
Categorical([True, False], name='correl_mfi_close-enabled'),
|
||||
Categorical([True, False], name='correl_hist_close-enabled'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='ema-enabled'),
|
||||
Categorical([True, False], name='sar-enabled'),
|
||||
Categorical([True, False], name='ema_bol-enabled'),
|
||||
Categorical(['mfi', 'macd_cross_signal', 'bol_low', 'bol_mid', 'ma_cross'], name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 120, name='roi_t1'),
|
||||
Integer(10, 60, name='roi_t2'),
|
||||
Integer(10, 40, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
240
.env/bin/user_data/hyperopts/hyper_ethusdt2.py
Normal file
240
.env/bin/user_data/hyperopts/hyper_ethusdt2.py
Normal file
@@ -0,0 +1,240 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper_ethusdt2(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('ao-enabled'):
|
||||
conditions.append(dataframe['ao'] > params['ao1-value'])
|
||||
conditions.append(dataframe['ao'] < params['ao2-value'])
|
||||
if params.get('angle_tsf_mid-enabled'):
|
||||
conditions.append(dataframe['angle_tsf_mid'] < params['angle_tsf_mid-value'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(params['rsi1-value'] < dataframe['rsi'])
|
||||
conditions.append(params['rsi2-value'] > dataframe['rsi'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'ao_cross':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['ao'], 0
|
||||
))
|
||||
if params['trigger'] == 'angle_tsf_mid_cross_up':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['angle_tsf_mid'], -50
|
||||
))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-50, 50, name='ao1-value'),
|
||||
Integer(-50, 50, name='ao2-value'),
|
||||
Integer(-87, 85, name='angle_tsf_mid-value'),
|
||||
Integer(8, 92, name='rsi1-value'),
|
||||
Integer(8, 92, name='rsi2-value'),
|
||||
Categorical([True, False], name='ao-enabled'),
|
||||
Categorical([True, False], name='angle_tsf_mid-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['ao_cross', 'angle_tsf_mid_cross_up'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('ao-enabled'):
|
||||
conditions.append(dataframe['ao'] > params['ao1-value_sell'])
|
||||
conditions.append(dataframe['ao'] < params['ao2-value_sell'])
|
||||
if params.get('angle_tsf_mid-enabled'):
|
||||
conditions.append(dataframe['angle_tsf_mid'] > params['angle_tsf_mid-value_sell'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(params['rsi1-value_sell'] < dataframe['rsi'])
|
||||
conditions.append(params['rsi2-value_sell'] > dataframe['rsi'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'ao_cross_dw':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['ao'], 0
|
||||
))
|
||||
if params['trigger'] == 'angle_tsf_mid_cross_dw':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['angle_tsf_mid'], 50
|
||||
))
|
||||
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-50, 50, name='ao1-value_sell'),
|
||||
Integer(-50, 50, name='ao2-value_sell'),
|
||||
Integer(-87, 85, name='angle_tsf_mid-value_sell'),
|
||||
Integer(8, 92, name='rsi1-value_sell'),
|
||||
Integer(8, 92, name='rsi2-value_sell'),
|
||||
Categorical([True, False], name='ao-enabled'),
|
||||
Categorical([True, False], name='angle_tsf_mid-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['angle_tsf_mid_cross_dw', 'ao_cross_dw'], name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(60, 600, name='roi_t1'),
|
||||
Integer(300, 1000, name='roi_t2'),
|
||||
Integer(500, 1500, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
285
.env/bin/user_data/hyperopts/hyper_ethusdt3.py
Normal file
285
.env/bin/user_data/hyperopts/hyper_ethusdt3.py
Normal file
@@ -0,0 +1,285 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper_ethusdt3(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('correl_h_l_30-enabled'):
|
||||
conditions.append(params['correl_h_l_30-value'] < dataframe['correl_h_l_30'])
|
||||
if params.get('correl_h_l_10-enabled'):
|
||||
conditions.append(params['correl_h_l_10-value'] < dataframe['correl_h_l_10'])
|
||||
if params.get('correl_h_l_3-enabled'):
|
||||
conditions.append(params['correl_h_l_3-value'] < dataframe['correl_h_l_3'])
|
||||
if params.get('cci_45-enabled'):
|
||||
conditions.append(params['cci_45-value'] > dataframe['cci_45'])
|
||||
if params.get('cci_30-enabled'):
|
||||
conditions.append(params['cci_30-value'] > dataframe['cci_30'])
|
||||
if params.get('natr-enabled'):
|
||||
conditions.append(params['natr-value'] < dataframe['natr'])
|
||||
if params.get('trend_line-enabled'):
|
||||
conditions.append(params['trend_line-value'] < (dataframe['trend_line'] - dataframe['close']))
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
|
||||
if params['trigger'] == 'correl_h_l_3':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['correl_h_l_30'], 0))
|
||||
if params['trigger'] == 'correl_h_l_10':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['correl_h_l_3'], 0))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['sar'], dataframe['close']))
|
||||
if params['trigger'] == 'cci_30':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['cci_30'], -50))
|
||||
if params['trigger'] == 'cci_45':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['cci_45'], -50))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(0.0, 4.2, name='natr-value'),
|
||||
Integer(-139, 105, name='trend_line-value'),
|
||||
Real(-1, 1, name='correl_h_l_3-value'),
|
||||
Real(-1, 1, name='correl_h_l_30-value'),
|
||||
Real(-1, 1, name='correl_h_l_10-value'),
|
||||
Integer(-200, 200, name='cci_30-value'),
|
||||
Integer(-200, 200, name='cci_45-value'),
|
||||
Categorical([True, False], name='correl_h_l_3-enabled'),
|
||||
Categorical([True, False], name='correl_h_l_30-enabled'),
|
||||
Categorical([True, False], name='correl_h_l_10-enabled'),
|
||||
Categorical([True, False], name='cci_30-enabled'),
|
||||
Categorical([True, False], name='cci_45-enabled'),
|
||||
Categorical([True, False], name='trend_line-enabled'),
|
||||
Categorical([True, False], name='natr-enabled'),
|
||||
|
||||
Categorical(
|
||||
['sar', 'correl_h_l_3', 'correl_h_l_10' 'cci_45', 'cci_30'],
|
||||
name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('correl_h_l_30-enabled'):
|
||||
conditions.append(params['correl_h_l_30-value_sell'] < dataframe['correl_h_l_30'])
|
||||
if params.get('correl_h_l_10-enabled'):
|
||||
conditions.append(params['correl_h_l_10-value_sell'] < dataframe['correl_h_l_10'])
|
||||
if params.get('correl_h_l_3-enabled'):
|
||||
conditions.append(params['correl_h_l_3-value_sell'] < dataframe['correl_h_l_3'])
|
||||
if params.get('cci_45-enabled'):
|
||||
conditions.append(params['cci_45-value_sell'] > dataframe['cci_45'])
|
||||
if params.get('cci_30-enabled'):
|
||||
conditions.append(params['cci_30-value_sell'] > dataframe['cci_30'])
|
||||
if params.get('natr-enabled'):
|
||||
conditions.append(params['natr-value_sell'] < dataframe['natr'])
|
||||
if params.get('trend_line-enabled'):
|
||||
conditions.append(params['trend_line-value_sell'] < (dataframe['trend_line'] - dataframe['close']))
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
|
||||
if params['trigger'] == 'correl_h_l_3':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['correl_h_l_30'], 0))
|
||||
if params['trigger'] == 'correl_h_l_10':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['correl_h_l_3'], 0))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['sar'], dataframe['close']))
|
||||
if params['trigger'] == 'cci_30':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['cci_30'], -50))
|
||||
if params['trigger'] == 'cci_45':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['cci_45'], -50))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(0.0, 4.2, name='natr-value_sell'),
|
||||
Integer(-139, 105, name='trend_line-value_sell'),
|
||||
Real(-1, 1, name='correl_h_l_3-value_sell'),
|
||||
Real(-1, 1, name='correl_h_l_30-value_sell'),
|
||||
Real(-1, 1, name='correl_h_l_10-value_sell'),
|
||||
Integer(-200, 200, name='cci_30-value_sell'),
|
||||
Integer(-200, 200, name='cci_45-value_sell'),
|
||||
Categorical([True, False], name='correl_h_l_3-enabled'),
|
||||
Categorical([True, False], name='correl_h_l_30-enabled'),
|
||||
Categorical([True, False], name='correl_h_l_10-enabled'),
|
||||
Categorical([True, False], name='cci_30-enabled'),
|
||||
Categorical([True, False], name='cci_45-enabled'),
|
||||
Categorical([True, False], name='trend_line-enabled'),
|
||||
Categorical([True, False], name='natr-enabled'),
|
||||
|
||||
Categorical(
|
||||
['sar', 'correl_h_l_3', 'correl_h_l_10' 'cci_45', 'cci_30'],
|
||||
name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 120, name='roi_t1'),
|
||||
Integer(10, 60, name='roi_t2'),
|
||||
Integer(10, 40, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
290
.env/bin/user_data/hyperopts/hyper_ethusdt_high_risk.py
Normal file
290
.env/bin/user_data/hyperopts/hyper_ethusdt_high_risk.py
Normal file
@@ -0,0 +1,290 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper_ethusdt_high_risk(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('ao-enabled'):
|
||||
conditions.append(dataframe['ao'] > params['ao-value'])
|
||||
if params.get('vwap_short-enabled'):
|
||||
conditions.append(params['vwap_short-value'] > dataframe['vwap_short'])
|
||||
if params.get('correl_h_l_3-enabled'):
|
||||
conditions.append(params['correl_h_l_3-value'] < dataframe['correl_h_l_3'])
|
||||
if params.get('cci_45-enabled'):
|
||||
conditions.append(params['cci_45-value'] > dataframe['cci_45'])
|
||||
if params.get('cci_30-enabled'):
|
||||
conditions.append(params['cci_30-value'] > dataframe['cci_30'])
|
||||
if params.get('natr-enabled'):
|
||||
conditions.append(params['natr-value'] < dataframe['natr'])
|
||||
if params.get('trend_line-enabled'):
|
||||
conditions.append(params['trend_line-value'] < (dataframe['trend_line'] - dataframe['close']))
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'ao_cross':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['ao'], 0
|
||||
))
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['sar'], dataframe['close']))
|
||||
if params['trigger'] == 'cci_30':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['cci_30'], -50))
|
||||
if params['trigger'] == 'cci_45':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['cci_45'], -50))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(0.0, 4.2, name='ao-value'),
|
||||
Integer(-139, 105, name='trend_line-value'),
|
||||
Real(-1, 1, name='correl_h_l_3-value'),
|
||||
Real(-1, 1, name='correl_h_l_30-value'),
|
||||
Real(-1, 1, name='correl_h_l_10-value'),
|
||||
Integer(-200, 200, name='cci_30-value'),
|
||||
Integer(-200, 200, name='cci_45-value'),
|
||||
Categorical([True, False], name='ao-enabled'),
|
||||
Categorical([True, False], name='correl_h_l_30-enabled'),
|
||||
Categorical([True, False], name='correl_h_l_10-enabled'),
|
||||
Categorical([True, False], name='cci_30-enabled'),
|
||||
Categorical([True, False], name='cci_45-enabled'),
|
||||
Categorical([True, False], name='trend_line-enabled'),
|
||||
Categorical([True, False], name='natr-enabled'),
|
||||
|
||||
Categorical(
|
||||
['ao_cross', 'macd_cross_signal', 'correl_h_l_10' 'cci_45', 'cci_30'],
|
||||
name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('correl_h_l_30-enabled'):
|
||||
conditions.append(params['correl_h_l_30-value_sell'] < dataframe['correl_h_l_30'])
|
||||
if params.get('correl_h_l_10-enabled'):
|
||||
conditions.append(params['correl_h_l_10-value_sell'] < dataframe['correl_h_l_10'])
|
||||
if params.get('correl_h_l_3-enabled'):
|
||||
conditions.append(params['correl_h_l_3-value_sell'] < dataframe['correl_h_l_3'])
|
||||
if params.get('cci_45-enabled'):
|
||||
conditions.append(params['cci_45-value_sell'] > dataframe['cci_45'])
|
||||
if params.get('cci_30-enabled'):
|
||||
conditions.append(params['cci_30-value_sell'] > dataframe['cci_30'])
|
||||
if params.get('natr-enabled'):
|
||||
conditions.append(params['natr-value_sell'] < dataframe['natr'])
|
||||
if params.get('trend_line-enabled'):
|
||||
conditions.append(params['trend_line-value_sell'] < (dataframe['trend_line'] - dataframe['close']))
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
|
||||
if params['trigger'] == 'ao_cross':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['ao'], 0
|
||||
))
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['macd'], dataframe['macdsignal']
|
||||
))
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['sar'], dataframe['close']))
|
||||
if params['trigger'] == 'cci_30':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['cci_30'], -50))
|
||||
if params['trigger'] == 'cci_45':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['cci_45'], -50))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(0.0, 4.2, name='natr-value_sell'),
|
||||
Integer(-139, 105, name='trend_line-value_sell'),
|
||||
Real(-1, 1, name='correl_h_l_3-value_sell'),
|
||||
Real(-1, 1, name='correl_h_l_30-value_sell'),
|
||||
Real(-1, 1, name='correl_h_l_10-value_sell'),
|
||||
Integer(-200, 200, name='cci_30-value_sell'),
|
||||
Integer(-200, 200, name='cci_45-value_sell'),
|
||||
Categorical([True, False], name='correl_h_l_3-enabled'),
|
||||
Categorical([True, False], name='correl_h_l_30-enabled'),
|
||||
Categorical([True, False], name='correl_h_l_10-enabled'),
|
||||
Categorical([True, False], name='cci_30-enabled'),
|
||||
Categorical([True, False], name='cci_45-enabled'),
|
||||
Categorical([True, False], name='trend_line-enabled'),
|
||||
Categorical([True, False], name='natr-enabled'),
|
||||
|
||||
Categorical(
|
||||
['sar', 'macd_cross_signal', 'correl_h_l_10' 'cci_45', 'cci_30'],
|
||||
name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 120, name='roi_t1'),
|
||||
Integer(10, 60, name='roi_t2'),
|
||||
Integer(10, 40, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
240
.env/bin/user_data/hyperopts/hyper_ltcusdt_1h.py
Normal file
240
.env/bin/user_data/hyperopts/hyper_ltcusdt_1h.py
Normal file
@@ -0,0 +1,240 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper_ltcusdt_1h(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('ao-enabled'):
|
||||
conditions.append(dataframe['ao'] > params['ao1-value'])
|
||||
conditions.append(dataframe['ao'] < params['ao2-value'])
|
||||
if params.get('angle_tsf_mid-enabled'):
|
||||
conditions.append(dataframe['angle_tsf_mid'] < params['angle_tsf_mid-value'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(params['rsi1-value'] < dataframe['rsi'])
|
||||
conditions.append(params['rsi2-value'] > dataframe['rsi'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['sar'], dataframe['close']
|
||||
))
|
||||
if params['trigger'] == 'sine':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['leadsine'], dataframe['sine']
|
||||
))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-50, 50, name='ao1-value'),
|
||||
Integer(-50, 50, name='ao2-value'),
|
||||
Integer(-87, 85, name='angle_tsf_mid-value'),
|
||||
Integer(8, 92, name='rsi1-value'),
|
||||
Integer(8, 92, name='rsi2-value'),
|
||||
Categorical([True, False], name='ao-enabled'),
|
||||
Categorical([True, False], name='angle_tsf_mid-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['sar', 'sine'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('ao-enabled'):
|
||||
conditions.append(dataframe['ao'] > params['ao1-value_sell'])
|
||||
conditions.append(dataframe['ao'] < params['ao2-value_sell'])
|
||||
if params.get('angle_tsf_mid-enabled'):
|
||||
conditions.append(dataframe['angle_tsf_mid'] > params['angle_tsf_mid-value_sell'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(params['rsi1-value_sell'] < dataframe['rsi'])
|
||||
conditions.append(params['rsi2-value_sell'] > dataframe['rsi'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'sar':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['sar'], dataframe['close']
|
||||
))
|
||||
if params['trigger'] == 'sine':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['leadsine'], dataframe['sine']
|
||||
))
|
||||
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-50, 50, name='ao1-value_sell'),
|
||||
Integer(-50, 50, name='ao2-value_sell'),
|
||||
Integer(-87, 85, name='angle_tsf_mid-value_sell'),
|
||||
Integer(8, 92, name='rsi1-value_sell'),
|
||||
Integer(8, 92, name='rsi2-value_sell'),
|
||||
Categorical([True, False], name='ao-enabled'),
|
||||
Categorical([True, False], name='angle_tsf_mid-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['sar', 'sine'], name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(60, 600, name='roi_t1'),
|
||||
Integer(300, 1000, name='roi_t2'),
|
||||
Integer(500, 1500, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
240
.env/bin/user_data/hyperopts/hyper_ltcusdt_1hpy
Normal file
240
.env/bin/user_data/hyperopts/hyper_ltcusdt_1hpy
Normal file
@@ -0,0 +1,240 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 hyper_ethusdt2(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('ao-enabled'):
|
||||
conditions.append(dataframe['ao'] > params['ao1-value'])
|
||||
conditions.append(dataframe['ao'] < params['ao2-value'])
|
||||
if params.get('angle_tsf_mid-enabled'):
|
||||
conditions.append(dataframe['angle_tsf_mid'] < params['angle_tsf_mid-value'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(params['rsi1-value'] < dataframe['rsi'])
|
||||
conditions.append(params['rsi2-value'] > dataframe['rsi'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'ao_cross':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['ao'], 0
|
||||
))
|
||||
if params['trigger'] == 'angle_tsf_mid_cross_up':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['angle_tsf_mid'], -50
|
||||
))
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-50, 50, name='ao1-value'),
|
||||
Integer(-50, 50, name='ao2-value'),
|
||||
Integer(-87, 85, name='angle_tsf_mid-value'),
|
||||
Integer(8, 92, name='rsi1-value'),
|
||||
Integer(8, 92, name='rsi2-value'),
|
||||
Categorical([True, False], name='ao-enabled'),
|
||||
Categorical([True, False], name='angle_tsf_mid-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['ao_cross', 'angle_tsf_mid_cross_up'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('ao-enabled'):
|
||||
conditions.append(dataframe['ao'] > params['ao1-value_sell'])
|
||||
conditions.append(dataframe['ao'] < params['ao2-value_sell'])
|
||||
if params.get('angle_tsf_mid-enabled'):
|
||||
conditions.append(dataframe['angle_tsf_mid'] > params['angle_tsf_mid-value_sell'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(params['rsi1-value_sell'] < dataframe['rsi'])
|
||||
conditions.append(params['rsi2-value_sell'] > dataframe['rsi'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'ao_cross_dw':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['ao'], 0
|
||||
))
|
||||
if params['trigger'] == 'angle_tsf_mid_cross_dw':
|
||||
conditions.append(qtpylib.crossed_below(
|
||||
dataframe['angle_tsf_mid'], 50
|
||||
))
|
||||
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(-50, 50, name='ao1-value_sell'),
|
||||
Integer(-50, 50, name='ao2-value_sell'),
|
||||
Integer(-87, 85, name='angle_tsf_mid-value_sell'),
|
||||
Integer(8, 92, name='rsi1-value_sell'),
|
||||
Integer(8, 92, name='rsi2-value_sell'),
|
||||
Categorical([True, False], name='ao-enabled'),
|
||||
Categorical([True, False], name='angle_tsf_mid-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['angle_tsf_mid_cross_dw', 'ao_cross_dw'], name='trigger')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
||||
"""
|
||||
Generate the ROI table that will be used by Hyperopt
|
||||
|
||||
This implementation generates the default legacy Freqtrade ROI tables.
|
||||
|
||||
Change it if you need different number of steps in the generated
|
||||
ROI tables or other structure of the ROI tables.
|
||||
|
||||
Please keep it aligned with parameters in the 'roi' optimization
|
||||
hyperspace defined by the roi_space method.
|
||||
"""
|
||||
roi_table = {}
|
||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
||||
|
||||
return roi_table
|
||||
|
||||
@staticmethod
|
||||
def roi_space() -> List[Dimension]:
|
||||
"""
|
||||
Values to search for each ROI steps
|
||||
|
||||
Override it if you need some different ranges for the parameters in the
|
||||
'roi' optimization hyperspace.
|
||||
|
||||
Please keep it aligned with the implementation of the
|
||||
generate_roi_table method.
|
||||
"""
|
||||
return [
|
||||
Integer(60, 600, name='roi_t1'),
|
||||
Integer(300, 1000, name='roi_t2'),
|
||||
Integer(500, 1500, name='roi_t3'),
|
||||
Real(0.01, 0.04, name='roi_p1'),
|
||||
Real(0.01, 0.07, name='roi_p2'),
|
||||
Real(0.01, 0.20, name='roi_p3'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def stoploss_space() -> List[Dimension]:
|
||||
"""
|
||||
Stoploss Value to search
|
||||
|
||||
Override it if you need some different range for the parameter in the
|
||||
'stoploss' optimization hyperspace.
|
||||
"""
|
||||
return [
|
||||
Real(-0.25, -0.02, name='stoploss'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def trailing_space() -> List[Dimension]:
|
||||
"""
|
||||
Create a trailing stoploss space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
return [
|
||||
# It was decided to always set trailing_stop is to True if the 'trailing' hyperspace
|
||||
# is used. Otherwise hyperopt will vary other parameters that won't have effect if
|
||||
# trailing_stop is set False.
|
||||
# This parameter is included into the hyperspace dimensions rather than assigning
|
||||
# it explicitly in the code in order to have it printed in the results along with
|
||||
# other 'trailing' hyperspace parameters.
|
||||
Categorical([True], name='trailing_stop'),
|
||||
|
||||
Real(0.01, 0.35, name='trailing_stop_positive'),
|
||||
|
||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
||||
# so this intermediate parameter is used as the value of the difference between
|
||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
||||
# generate_trailing_params() method.
|
||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
||||
Real(0.001, 0.1, name='trailing_stop_positive_offset_p1'),
|
||||
|
||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
||||
]
|
||||
173
.env/bin/user_data/hyperopts/macd_hyper.py
Normal file
173
.env/bin/user_data/hyperopts/macd_hyper.py
Normal file
@@ -0,0 +1,173 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 macd(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('mfi-enabled'):
|
||||
conditions.append((dataframe['macdhist']) > params['macd_diff'])
|
||||
conditions.append((dataframe['macdhist']) > params['macd_diff'])
|
||||
if params.get('fastd-enabled'):
|
||||
conditions.append(dataframe['fastd'] < params['fastd-value'])
|
||||
if params.get('adx-enabled'):
|
||||
conditions.append(dataframe['adx'] > params['adx-value'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(dataframe['rsi'] < params['rsi-value'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'sr':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['sr_fastk'], dataframe['sr_fastd']))
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['macd'], dataframe['macdsignal']))
|
||||
if params['trigger'] == 'macd_histogram':
|
||||
conditions.append(dataframe['macdhist'] - dataframe['macdhist'].shift(1))
|
||||
if params['trigger'] == 'slow':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['slowk'], dataframe['slowd']))
|
||||
if params['trigger'] == 'sf_fast':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['sf_fastk'], dataframe['sf_fastd']))
|
||||
if params['trigger'] == 'tema':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['close'], dataframe['tema']))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(10, 25, name='mfi-value'),
|
||||
Integer(15, 45, name='fastd-value'),
|
||||
Integer(20, 50, name='adx-value'),
|
||||
Integer(20, 40, name='rsi-value'),
|
||||
Categorical([True, False], name='mfi-enabled'),
|
||||
Categorical([True, False], name='fastd-enabled'),
|
||||
Categorical([True, False], name='adx-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical(['sr', 'macd_cross_signal', 'macd_histogram', 'slow', 'sf_fast', 'tema'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('sell-mfi-enabled'):
|
||||
conditions.append(dataframe['mfi'] > params['sell-mfi-value'])
|
||||
if params.get('sell-fastd-enabled'):
|
||||
conditions.append(dataframe['fastd'] > params['sell-fastd-value'])
|
||||
if params.get('sell-adx-enabled'):
|
||||
conditions.append(dataframe['adx'] < params['sell-adx-value'])
|
||||
if params.get('sell-rsi-enabled'):
|
||||
conditions.append(dataframe['rsi'] > params['sell-rsi-value'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'sell-trigger' in params:
|
||||
if params['sell-trigger'] == 'sell-bb_upper':
|
||||
conditions.append(dataframe['close'] > dataframe['bb_upperband'])
|
||||
if params['sell-trigger'] == 'sell-macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['macdsignal'], dataframe['macd']
|
||||
))
|
||||
if params['sell-trigger'] == 'sell-sar_reversal':
|
||||
conditions.append(qtpylib.crossed_above(
|
||||
dataframe['sar'], dataframe['close']
|
||||
))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(75, 100, name='sell-mfi-value'),
|
||||
Integer(50, 100, name='sell-fastd-value'),
|
||||
Integer(50, 100, name='sell-adx-value'),
|
||||
Integer(60, 100, name='sell-rsi-value'),
|
||||
Categorical([True, False], name='sell-mfi-enabled'),
|
||||
Categorical([True, False], name='sell-fastd-enabled'),
|
||||
Categorical([True, False], name='sell-adx-enabled'),
|
||||
Categorical([True, False], name='sell-rsi-enabled'),
|
||||
Categorical(['sell-bb_upper',
|
||||
'sell-macd_cross_signal',
|
||||
'sell-sar_reversal'], name='sell-trigger')
|
||||
]
|
||||
219
.env/bin/user_data/hyperopts/quick_ethusdt_1m_hyper.py
Normal file
219
.env/bin/user_data/hyperopts/quick_ethusdt_1m_hyper.py
Normal file
@@ -0,0 +1,219 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- 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 quick_ethusdt_1m_hyper(IHyperOpt):
|
||||
"""
|
||||
This is a Hyperopt template to get you started.
|
||||
|
||||
More information in the documentation: https://www.freqtrade.io/en/latest/hyperopt/
|
||||
|
||||
You should:
|
||||
- Add any lib you need to build your hyperopt.
|
||||
|
||||
You must keep:
|
||||
- The prototypes for the methods: populate_indicators, indicator_space, buy_strategy_generator.
|
||||
|
||||
The methods roi_space, generate_roi_table and stoploss_space are not required
|
||||
and are provided by default.
|
||||
However, you may override them if you need 'roi' and 'stoploss' spaces that
|
||||
differ from the defaults offered by Freqtrade.
|
||||
Sample implementation of these methods will be copied to `user_data/hyperopts` when
|
||||
creating the user-data directory using `freqtrade create-userdir --userdir user_data`,
|
||||
or is available online under the following URL:
|
||||
https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py.
|
||||
"""
|
||||
|
||||
@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
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append((dataframe['macdhist']) > params['macdhist_diff_buy'])
|
||||
if params.get('macd_angle-enabled'):
|
||||
conditions.append((dataframe['macd_angle']) > params['macd_angle_buy'])
|
||||
if params.get('tema-enabled'):
|
||||
conditions.append(dataframe['tema'] < params['tema_value_buy'])
|
||||
if params.get('sr_fastd-enabled'):
|
||||
conditions.append(dataframe['sr_fastd'] > params['sr_fastd_value_buy'])
|
||||
if params.get('sr_fastd_angle-enabled'):
|
||||
conditions.append(dataframe['sr_fastd_angle'] > params['sr_fastd_angle_value_buy'])
|
||||
if params.get('slowk-enabled'):
|
||||
conditions.append(dataframe['slowk'] > params['slowk_value_buy'])
|
||||
if params.get('slowd_angle-enabled'):
|
||||
conditions.append(dataframe['slowd_angle'] > params['slowd_angle_value_buy'])
|
||||
if params.get('sf_fastk-enabled'):
|
||||
conditions.append(dataframe['sf_fastk'] > params['sf_fastk_value_buy'])
|
||||
if params.get('sf_fastd_angle-enabled'):
|
||||
conditions.append(dataframe['sf_fastd_angle'] > params['sf_fastd_angle_value_buy'])
|
||||
if params.get('rsi-enabled'):
|
||||
conditions.append(dataframe['rsi'] > params['rsi_value_buy'])
|
||||
if params.get('rsi_angle-enabled'):
|
||||
conditions.append(dataframe['rsi_angle'] > params['rsi_angle_value_buy'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'trigger' in params:
|
||||
if params['trigger'] == 'sr':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['sr_fastk'], dataframe['sr_fastd']))
|
||||
if params['trigger'] == 'macd_cross_signal':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['macd'], dataframe['macdsignal']))
|
||||
if params['trigger'] == 'macd_histogram':
|
||||
conditions.append((dataframe['macdhist'] - dataframe['macdhist'].shift(1)) > 0)
|
||||
if params['trigger'] == 'slow':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['slowk'], dataframe['slowd']))
|
||||
if params['trigger'] == 'sf_fast':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['sf_fastk'], dataframe['sf_fastd']))
|
||||
if params['trigger'] == 'tema':
|
||||
conditions.append(qtpylib.crossed_above(dataframe['close'], dataframe['tema']))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(-0.00072, 0.0008, name='macdhist_diff_buy'),
|
||||
Real(-0.019, 0.018, name='macd_angle_buy'),
|
||||
Real(0.016, 0.13, name='tema_value_buy'),
|
||||
Integer(0, 100, name='sr_fastd_value_buy'),
|
||||
Integer(-90, 90, name='sr_fastd_angle_value_buy'),
|
||||
Integer(0, 100, name='slowk_value_buy'),
|
||||
Integer(-90, 90, name='slowd_angle_value_buy'),
|
||||
Integer(0, 100, name='sf_fastk_value_buy'),
|
||||
Integer(-90, 90, name='sf_fastd_angle_value_buy'),
|
||||
Integer(0, 100, name='rsi_value_buy'),
|
||||
Integer(-90, 90, name='rsi_angle_value_buy'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='macd_angle-enabled'),
|
||||
Categorical([True, False], name='tema-enabled'),
|
||||
Categorical([True, False], name='sr_fastd-enabled'),
|
||||
Categorical([True, False], name='sr_fastd_angle-enabled'),
|
||||
Categorical([True, False], name='slowk-enabled'),
|
||||
Categorical([True, False], name='slowd_angle-enabled'),
|
||||
Categorical([True, False], name='sf_fastk-enabled'),
|
||||
Categorical([True, False], name='sf_fastk_angle-enabled'),
|
||||
Categorical([True, False], name='rsi-enabled'),
|
||||
Categorical([True, False], name='rsi_angle-enabled'),
|
||||
Categorical(['sr', 'macd_cross_signal', 'macd_histogram', 'slow', 'sf_fast', 'tema'], name='trigger')
|
||||
]
|
||||
|
||||
@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
|
||||
if params.get('macd-enabled'):
|
||||
conditions.append((dataframe['macdhist']) < params['macdhist_diff_sell'])
|
||||
if params.get('macd_angle-enabled'):
|
||||
conditions.append((dataframe['macd_angle']) < params['macd_angle_sell'])
|
||||
if params.get('tema-enabled'):
|
||||
conditions.append(dataframe['tema'] < params['tema_value_sell'])
|
||||
if params.get('sr_fastd-enabled'):
|
||||
conditions.append(dataframe['sr_fastd'] < params['sr_fastd_value_sell'])
|
||||
if params.get('sr_fastd_angle-enabled'):
|
||||
conditions.append(dataframe['sr_fastd_angle'] > params['sr_fastd_angle_value_sell'])
|
||||
if params.get('slowk-enabled'):
|
||||
conditions.append(dataframe['slowk'] < params['slowk_value_sell'])
|
||||
if params.get('slowd_angle-enabled'):
|
||||
conditions.append(dataframe['slowd_angle'] < params['slowd_angle_value_sell'])
|
||||
if params.get('sf_fastk-enabled'):
|
||||
conditions.append(dataframe['sf_fastk'] > params['sf_fastk_value_sell'])
|
||||
if params.get('sf_fastd_angle-enabled'):
|
||||
conditions.append(dataframe['sf_fastd_angle'] < params['sf_fastd_angle_value_sell'])
|
||||
|
||||
# TRIGGERS
|
||||
if 'sell-trigger' in params:
|
||||
if params['trigger'] == 'sr':
|
||||
conditions.append(qtpylib.crossed_below(dataframe['sr_fastk'], dataframe['sr_fastd']))
|
||||
if params['trigger'] == 'macd_histogram':
|
||||
conditions.append((dataframe['macdhist'] - dataframe['macdhist'].shift(1)) < 0)
|
||||
if params['trigger'] == 'slow':
|
||||
conditions.append(qtpylib.crossed_below(dataframe['slowk'], dataframe['slowd']))
|
||||
if params['trigger'] == 'sf_fast':
|
||||
conditions.append(qtpylib.crossed_below(dataframe['sf_fastk'], dataframe['sf_fastd']))
|
||||
if params['trigger'] == 'tema':
|
||||
conditions.append(qtpylib.crossed_below(dataframe['close'], dataframe['tema']))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'sell'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Real(-0.00072, 0.0008, name='macdhist_diff_sell'),
|
||||
Real(-0.019, 0.018, name='macd_angle_sell'),
|
||||
Real(0.016, 0.13, name='tema_value_sell'),
|
||||
Integer(0, 100, name='sr_fastd_value_sell'),
|
||||
Integer(-90, 90, name='sr_fastd_angle_value_sell'),
|
||||
Integer(0, 100, name='slowk_value_sell'),
|
||||
Integer(-90, 90, name='slowd_angle_value_sell'),
|
||||
Integer(0, 100, name='sf_fastk_value_sell'),
|
||||
Integer(-90, 90, name='sf_fastd_angle_value_sell'),
|
||||
Categorical([True, False], name='macd-enabled'),
|
||||
Categorical([True, False], name='macd_angle-enabled'),
|
||||
Categorical([True, False], name='tema-enabled'),
|
||||
Categorical([True, False], name='sr_fastd-enabled'),
|
||||
Categorical([True, False], name='sr_fastd_angle-enabled'),
|
||||
Categorical([True, False], name='slowk-enabled'),
|
||||
Categorical([True, False], name='slowd_angle-enabled'),
|
||||
Categorical([True, False], name='sf_fastk-enabled'),
|
||||
Categorical([True, False], name='sf_fastk_angle-enabled'),
|
||||
Categorical(['sr', 'macd_histogram', 'slow', 'sf_fast', 'tema'], name='trigger')
|
||||
|
||||
]
|
||||
Reference in New Issue
Block a user