MACDStrategy_hyperopt
♡15 related strategies (⧉ identical code, ≈ similar name)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | # pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement import talib.abstract as ta from pandas import DataFrame from typing import Dict, Any, Callable, List # import numpy as np from skopt.space import Categorical, Dimension, Integer, Real # import freqtrade.vendor.qtpylib.indicators as qtpylib from freqtrade.optimize.hyperopt_interface import IHyperOpt class_name = 'MACDStrategy_hyperopt' # This class is a sample. Feel free to customize it. class MACDStrategy_hyperopt(IHyperOpt): """ This is an Example hyperopt to inspire you. - corresponding to MACDStrategy in this repository. To run this, best use the following command (adjust to your environment if needed): ``` freqtrade hyperopt --strategy MACDStrategy --hyperopt MACDStrategy_hyperopt --spaces buy sell ``` The idea is to optimize only the CCI value. - Buy side: CCI between -700 and 0 - Sell side: CCI between 0 and 700 More information in https://github.com/freqtrade/freqtrade/blob/develop/docs/hyperopt.md """ @staticmethod def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] dataframe['cci'] = ta.CCI(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 """ dataframe.loc[ ( (dataframe['macd'] > dataframe['macdsignal']) & (dataframe['cci'] <= params['buy-cci-value']) & (dataframe['volume'] > 0) # Make sure Volume is not 0 ), 'buy'] = 1 return dataframe return populate_buy_trend @staticmethod def indicator_space() -> List[Dimension]: """ Define your Hyperopt space for searching strategy parameters """ return [ Integer(-700, 0, name='buy-cci-value'), ] @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 """ dataframe.loc[ ( (dataframe['macd'] < dataframe['macdsignal']) & (dataframe['cci'] >= params['sell-cci-value']) ), '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, 700, name='sell-cci-value'), ] |
Strategy League — fixed backtest that feeds the ranking
🤖 Machine-learning strategies can't be sandbox-tested for now — they need model libraries, trained model files and (for FreqAI) hours of training compute per run — so this strategy isn't League-ranked. Its code analysis, tags and bias checks above still apply.
Backtests — over a market period
Backtest this strategy over a chosen crypto-cycle period. These don't affect the League ranking, and need that period's candle data downloaded.
🤖 Not available for FreqAI/ML strategies for now — the sandbox has no model libraries or trained model files (see the Strategy League tab).
Log in or sign up to run backtests.
| Period | Range | Total % | Win % | Max DD | Trades | |
|---|---|---|---|---|---|---|
| 2020 · DeFi Summer & Pre-Halving Rally | 20200101-20210101 | not run | ||||
| 2021 · Institutional Bull Market | 20210101-20220101 | not run | ||||
| 2022 · Post-Bull Crash & Macro Tightening | 20220101-20230101 | not run | ||||
| 2023–2024 · Recovery & ETF Anticipation | 20230101-20250101 | not run | ||||
| 2025–2026 · Current Cycle | 20250101-20260101 | not run | ||||
Walk forward
🤖 Not available for FreqAI/ML strategies for now — the sandbox has no model libraries or trained model files (see the Strategy League tab).
Backtest trust check
Static source analysis — instant, does not run the strategy. Flags future-data leaks, backtest-realism problems, and indicators worth a second look.
Lookahead analysis
freqtrade lookahead-analysis: detects strategies peeking at future candles.