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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | # SupertrendFuturesStrategyV8_2 - 市场环境自适应版 # 基于V8.1,添加牛熊市识别和动态调整 import numpy as np import pandas as pd from pandas import DataFrame from datetime import datetime from typing import Optional from functools import reduce import logging from freqtrade.strategy import IStrategy, DecimalParameter, IntParameter import talib.abstract as ta logger = logging.getLogger(__name__) class SupertrendFuturesStrategyV8_2(IStrategy): """ V8.2: 市场环境自适应版 新增功能: 1. 市场环境识别(日线趋势) - 牛市:价格 > EMA200,做多优先 - 熊市:价格 < EMA200,做空优先 - 震荡:横盘整理,减少交易 2. 动态条件调整 - 牛市:放宽做多ADX(30),收紧做空ADX(35) - 熊市:放宽做空ADX(20),收紧做多ADX(40) - 震荡:ADX要求35+ 3. 杠杆动态调整 - 顺势交易:2x杠杆 - 逆势交易:1x杠杆 基础参数继承V8.1优化结果 """ INTERFACE_VERSION = 3 # V8.1 优化参数(从Hyperopt结果) atr_period = IntParameter(5, 30, default=21, space="buy") atr_multiplier = DecimalParameter(2.0, 5.0, default=4.622, space="buy") ema_fast = IntParameter(5, 50, default=21, space="buy") ema_slow = IntParameter(20, 200, default=47, space="buy") adx_threshold_long = IntParameter(20, 40, default=34, space="buy") adx_threshold_short = IntParameter(15, 35, default=23, space="buy") alpha_threshold = DecimalParameter(0.02, 0.15, default=0.118, space="buy") # V8.2 新增参数 - 市场环境 trend_lookback = IntParameter(50, 200, default=100, space="buy") # 趋势判断周期 bear_adx_bonus = IntParameter(5, 15, default=10, space="buy") # 熊市做空ADX放宽 bull_adx_penalty = IntParameter(5, 15, default=10, space="buy") # 牛市做空ADX收紧 minimal_roi = {"0": 0.06} stoploss = -0.03 timeframe = '30m' trailing_stop = True trailing_stop_positive = 0.02 trailing_stop_positive_offset = 0.03 trailing_only_offset_is_reached = True startup_candle_count = 200 order_types = { 'entry': 'limit', 'exit': 'limit', 'stoploss': 'market', 'stoploss_on_exchange': False } can_short: bool = True leverage_default = 2 def supertrend(self, dataframe, period=14, multiplier=3): """Supertrend计算""" df = dataframe.copy() hl2 = (df['high'] + df['low']) / 2 atr = ta.ATR(df, timeperiod=period) upperband = hl2 + (multiplier * atr) lowerband = hl2 - (multiplier * atr) supertrend = [0] * len(df) direction = [1] * len(df) for i in range(1, len(df)): if df['close'].iloc[i] > upperband.iloc[i-1]: direction[i] = 1 elif df['close'].iloc[i] < lowerband.iloc[i-1]: direction[i] = -1 else: direction[i] = direction[i-1] supertrend[i] = lowerband.iloc[i] if direction[i] == 1 else upperband.iloc[i] return pd.Series(supertrend, index=df.index), pd.Series(direction, index=df.index) def detect_market_regime(self, dataframe: DataFrame) -> DataFrame: """ 检测市场环境 返回: 1=牛市, -1=熊市, 0=震荡 """ # 使用长期EMA判断趋势 dataframe['ema_trend'] = ta.EMA(dataframe['close'], timeperiod=self.trend_lookback.value) # 价格相对位置 price_position = (dataframe['close'] - dataframe['ema_trend']) / dataframe['ema_trend'] * 100 # 趋势强度(ADX) adx = ta.ADX(dataframe, timeperiod=14) # 市场环境判断 - 放宽条件 conditions = [ (price_position > 2) & (adx > 20), # 牛市:放宽 (price_position < -2) & (adx > 20), # 熊市:放宽 ] choices = [1, -1] # 牛市=1, 熊市=-1 dataframe['market_regime'] = np.select(conditions, choices, default=0) return dataframe def leverage(self, pair, current_time, current_rate, proposed_leverage, max_leverage, entry_tag, side, **kwargs): """动态杠杆 - 顺势加仓,逆势减仓""" dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe) if len(dataframe) < 1: return min(self.leverage_default, max_leverage) last_candle = dataframe.iloc[-1] regime = last_candle.get('market_regime', 0) # 顺势交易:2x杠杆 # 逆势交易:1x杠杆 # 震荡市:1.5x杠杆 if regime == 1 and side == 'long': # 牛市做多 leverage = 2.0 elif regime == -1 and side == 'short': # 熊市做空 leverage = 2.0 elif regime == 1 and side == 'short': # 牛市做空(逆势) leverage = 1.0 elif regime == -1 and side == 'long': # 熊市做多(逆势) leverage = 1.0 else: # 震荡市 leverage = 1.5 return min(leverage, max_leverage) def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """计算技术指标""" # === V8.1 核心指标 === dataframe['ema_fast'] = ta.EMA(dataframe, timeperiod=self.ema_fast.value) dataframe['ema_slow'] = ta.EMA(dataframe, timeperiod=self.ema_slow.value) dataframe['supertrend'], dataframe['st_dir'] = self.supertrend( dataframe, period=self.atr_period.value, multiplier=self.atr_multiplier.value ) # ADX dataframe['adx'] = ta.ADX(dataframe, timeperiod=14) dataframe['adx_pos'] = ta.PLUS_DI(dataframe, timeperiod=14) dataframe['adx_neg'] = ta.MINUS_DI(dataframe, timeperiod=14) # RSI dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) # 成交量 dataframe['volume_ma'] = dataframe['volume'].rolling(window=20).mean() # Alpha#101 (简化版) dataframe['alpha_101'] = ( (dataframe['close'] - dataframe['close'].shift(5)) / dataframe['close'].shift(5) * 100 - (dataframe['volume'] - dataframe['volume'].shift(5)) / dataframe['volume'].shift(5) * 10 ) # 趋势判断 dataframe['is_uptrend'] = dataframe['close'] > dataframe['supertrend'] dataframe['is_downtrend'] = dataframe['close'] < dataframe['supertrend'] # 波动率 dataframe['volatility_ratio'] = ta.ATR(dataframe, timeperiod=14) / dataframe['close'] # === V8.2 新增:市场环境判断 === dataframe = self.detect_market_regime(dataframe) return dataframe def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """做多 - 根据市场环境调整条件""" dataframe.loc[:, 'enter_long'] = 0 # 获取当前市场环境 regime = dataframe['market_regime'].iloc[-1] if len(dataframe) > 0 else 0 # 根据市场环境调整ADX阈值 if regime == 1: # 牛市:放宽做多 adx_threshold = self.adx_threshold_long.value - 5 elif regime == -1: # 熊市:收紧做多 adx_threshold = self.adx_threshold_long.value + 10 else: # 震荡:标准 adx_threshold = self.adx_threshold_long.value conditions = [ # V8.1 核心条件 dataframe['st_dir'] == 1, dataframe['ema_fast'] > dataframe['ema_slow'], dataframe['adx'] > adx_threshold, dataframe['adx_pos'] > dataframe['adx_neg'], dataframe['close'] > dataframe['supertrend'], dataframe['is_uptrend'], # V8.1 多因子 (dataframe['rsi'] > 35) & (dataframe['rsi'] < 80), dataframe['alpha_101'] > self.alpha_threshold.value, dataframe['volume'] > dataframe['volume_ma'] * 1.1, dataframe['volatility_ratio'] < 0.06, ] if conditions: dataframe.loc[reduce(lambda x, y: x & y, conditions), 'enter_long'] = 1 return dataframe def populate_entry_trend_short(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """做空 - 根据市场环境调整条件""" dataframe.loc[:, 'enter_short'] = 0 # 获取当前市场环境 regime = dataframe['market_regime'].iloc[-1] if len(dataframe) > 0 else 0 # 根据市场环境调整ADX阈值 if regime == -1: # 熊市:放宽做空 adx_threshold = self.adx_threshold_short.value - self.bear_adx_bonus.value elif regime == 1: # 牛市:收紧做空 adx_threshold = self.adx_threshold_short.value + self.bull_adx_penalty.value else: # 震荡:标准 adx_threshold = self.adx_threshold_short.value conditions = [ # V8.1 核心条件 dataframe['st_dir'] == -1, dataframe['ema_fast'] < dataframe['ema_slow'], dataframe['adx'] > adx_threshold, dataframe['adx_neg'] > dataframe['adx_pos'], dataframe['close'] < dataframe['supertrend'], dataframe['is_downtrend'], # V8.1 多因子 (dataframe['rsi'] > 20) & (dataframe['rsi'] < 65), dataframe['alpha_101'] < -self.alpha_threshold.value, dataframe['volume'] > dataframe['volume_ma'] * 1.1, dataframe['volatility_ratio'] < 0.06, ] if conditions: dataframe.loc[reduce(lambda x, y: x & y, conditions), 'enter_short'] = 1 return dataframe def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """做多平仓""" dataframe.loc[:, 'exit_long'] = 0 conditions = [dataframe['st_dir'] == -1] if conditions: dataframe.loc[reduce(lambda x, y: x & y, conditions), 'exit_long'] = 1 return dataframe def populate_exit_trend_short(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """做空平仓""" dataframe.loc[:, 'exit_short'] = 0 conditions = [dataframe['st_dir'] == 1] if conditions: dataframe.loc[reduce(lambda x, y: x & y, conditions), 'exit_short'] = 1 return dataframe def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float, time_in_force: str, current_time: datetime, entry_tag: Optional[str], side: str, **kwargs) -> bool: """入场确认""" dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe) if len(dataframe) < 1: return False last_candle = dataframe.iloc[-1] # 避免极端波动 if last_candle['volatility_ratio'] > 0.08: logger.info(f"波动率过高,跳过 {pair}") return False return True |
Strategy League — fixed backtest that feeds the ranking
Export report Freqtrade logsRun finished · took 212.6s
ℹ️ This strategy uses a trailing stop — freqtrade only
re-checks these once per 30m candle by default, not against the price movement within it.
For a more accurate read, re-run this backtest locally with --timeframe-detail 1m. Freqle doesn't do this for every check here: multiplying every
League/sweep backtest by a finer detail timeframe is more compute than the sandbox can sustain
across every indexed strategy. why this matters →
- profit isn't statistically significant (p=1.00) — hard to tell apart from luck
- only 0% of resampled runs were profitable
- profitable in only 9% of rolling 3-month windows
- did not beat simply holding the market
- very deep drawdown (-91%)
Resampling the trade sequence 2,000× shows the spread of results this edge could plausibly produce — separating a dependable strategy from one that got lucky once.
Loading charts…
Monthly breakdown
| Month | Regime | Trades | Profit % | Avg % | Win | Loss | Win % | DD % | Avg dur |
|---|---|---|---|---|---|---|---|---|---|
| Nov 2024 | bullish trending low vol | 92 | -7.01 | -0.76 | 35 | 57 | 38.0 | -90.52 | 1h 34m |
| Oct 2024 | bullish choppy low vol | 25 | -2.63 | -1.03 | 10 | 15 | 40.0 | -83.74 | 9h 11m |
| Sep 2024 | bearish choppy low vol | 40 | -2.00 | -0.47 | 20 | 20 | 50.0 | -81.48 | 5h 12m |
| Aug 2024 | bearish choppy high vol | 32 | -2.30 | -0.77 | 14 | 18 | 43.8 | -79.67 | 4h 42m |
| Jul 2024 | bearish trending low vol | 66 | -0.77 | -0.14 | 35 | 31 | 53.0 | -77.04 | 5h 45m |
| Jun 2024 | bearish choppy low vol | 21 | -1.56 | -0.75 | 9 | 12 | 42.9 | -76.55 | 8h 10m |
| May 2024 | bullish choppy high vol | 56 | -2.41 | -0.44 | 27 | 29 | 48.2 | -74.79 | 3h 56m |
| Apr 2024 | bearish choppy high vol | 21 | -3.79 | -1.82 | 5 | 16 | 23.8 | -72.45 | 4h 00m |
| Mar 2024 | bullish trending high vol | 77 | -4.52 | -0.59 | 33 | 44 | 42.9 | -68.91 | 2h 09m |
| Feb 2024 | bullish trending low vol | 115 | -2.99 | -0.27 | 55 | 60 | 47.8 | -66.57 | 3h 20m |
| Jan 2024 | bearish choppy high vol | 67 | -2.97 | -0.44 | 29 | 38 | 43.3 | -62.67 | 1h 59m |
| Dec 2023 | bullish trending low vol | 104 | -0.80 | -0.08 | 53 | 51 | 51.0 | -59.82 | 2h 42m |
| Nov 2023 | bullish trending low vol | 95 | +0.78 | 0.08 | 52 | 43 | 54.7 | -59.1 | 4h 41m |
| Oct 2023 | bullish trending low vol | 86 | -0.61 | -0.07 | 46 | 40 | 53.5 | -59.52 | 8h 28m |
| Sep 2023 | bearish choppy low vol | 53 | -4.71 | -0.89 | 21 | 32 | 39.6 | -58.98 | 18h 08m |
| Aug 2023 | bearish choppy low vol | 28 | -1.50 | -0.54 | 11 | 17 | 39.3 | -53.5 | 8h 56m |
| Jul 2023 | bullish trending low vol | 63 | -2.34 | -0.37 | 27 | 36 | 42.9 | -52.05 | 3h 58m |
| Jun 2023 | bullish trending low vol | 59 | -0.16 | -0.03 | 27 | 32 | 45.8 | -51.08 | 1h 25m |
| May 2023 | bearish choppy low vol | 31 | -1.77 | -0.59 | 15 | 16 | 48.4 | -49.63 | 11h 05m |
| Apr 2023 | bullish trending low vol | 75 | -2.84 | -0.38 | 35 | 40 | 46.7 | -48.42 | 6h 19m |
| Mar 2023 | bullish trending high vol | 69 | -4.04 | -0.59 | 30 | 39 | 43.5 | -45.72 | 3h 26m |
| Feb 2023 | bullish trending low vol | 45 | -0.19 | -0.04 | 23 | 22 | 51.1 | -41.4 | 2h 57m |
| Jan 2023 | bullish trending low vol | 146 | +5.76 | 0.40 | 83 | 63 | 56.8 | -47.24 | 3h 59m |
| Dec 2022 | bearish trending low vol | 33 | -2.95 | -0.90 | 13 | 20 | 39.4 | -46.66 | 12h 12m |
| Nov 2022 | bearish trending high vol | 87 | -2.87 | -0.33 | 41 | 46 | 47.1 | -46.22 | 2h 17m |
| Oct 2022 | bullish choppy low vol | 55 | -0.18 | -0.05 | 28 | 27 | 50.9 | -43.2 | 5h 27m |
| Sep 2022 | bearish choppy high vol | 30 | -0.74 | -0.24 | 16 | 14 | 53.3 | -40.86 | 2h 47m |
| Aug 2022 | bullish choppy high vol | 74 | -7.18 | -0.98 | 30 | 44 | 40.5 | -40.54 | 3h 23m |
| Jul 2022 | bullish trending high vol | 114 | +5.30 | 0.47 | 58 | 56 | 50.9 | -39.91 | 0h 49m |
| Jun 2022 | bearish trending high vol | 40 | +0.43 | 0.10 | 17 | 23 | 42.5 | -39.32 | 1h 07m |
| May 2022 | bearish trending high vol | 22 | -0.19 | -0.12 | 10 | 12 | 45.5 | -39.37 | 1h 40m |
| Apr 2022 | bearish choppy high vol | 37 | +0.03 | -0.01 | 17 | 20 | 45.9 | -39.52 | 1h 15m |
| Mar 2022 | bullish choppy high vol | 54 | -1.20 | -0.21 | 26 | 28 | 48.1 | -40.15 | 2h 07m |
| Feb 2022 | bearish trending high vol | 14 | -0.95 | -0.69 | 6 | 8 | 42.9 | -37.7 | 6h 39m |
| Jan 2022 | bearish trending high vol | 12 | -0.58 | -0.48 | 5 | 7 | 41.7 | -36.88 | 7h 10m |
| Dec 2021 | bearish trending high vol | 10 | -1.86 | -1.86 | 2 | 8 | 20.0 | -36.12 | 0h 45m |
| Nov 2021 | bearish trending high vol | 50 | -6.68 | -1.42 | 16 | 34 | 32.0 | -34.16 | 3h 38m |
| Oct 2021 | bullish trending high vol | 46 | -1.33 | -0.32 | 22 | 24 | 47.8 | -28.32 | 3h 16m |
| Sep 2021 | bearish trending high vol | 49 | -0.47 | -0.11 | 22 | 27 | 44.9 | -26.41 | 0h 54m |
| Aug 2021 | bullish trending high vol | 106 | -6.46 | -0.63 | 42 | 64 | 39.6 | -25.96 | 0h 54m |
| Jul 2021 | bullish trending high vol | 65 | -4.27 | -0.68 | 29 | 36 | 44.6 | -19.77 | 2h 06m |
| Jun 2021 | bearish trending high vol | 31 | +0.36 | 0.11 | 17 | 14 | 54.8 | -16.54 | 0h 53m |
| May 2021 | bearish trending high vol | 56 | -4.02 | -0.74 | 21 | 35 | 37.5 | -16.4 | 0h 27m |
| Apr 2021 | bearish choppy high vol | 106 | -4.06 | -0.40 | 46 | 60 | 43.4 | -12.15 | 0h 52m |
| Mar 2021 | bullish choppy high vol | 130 | -7.19 | -0.59 | 51 | 79 | 39.2 | -8.76 | 1h 07m |
| Feb 2021 | bullish trending high vol | 197 | +3.67 | 0.18 | 94 | 103 | 47.7 | -7.69 | 0h 30m |
| Jan 2021 | bullish trending high vol | 177 | -1.45 | -0.09 | 76 | 101 | 42.9 | -3.95 | 0h 29m |
Yearly breakdown
| Year | Trades | Profit % | Avg % | Win | Loss | Win % | DD % | Avg dur |
|---|---|---|---|---|---|---|---|---|
| 2024 | 612 | -32.95 | -0.54 | 272 | 340 | 44.4 | -90.52 | 3h 42m |
| 2023 | 854 | -12.42 | -0.15 | 423 | 431 | 49.5 | -59.82 | 5h 35m |
| 2022 | 572 | -11.08 | -0.20 | 267 | 305 | 46.7 | -46.66 | 3h 03m |
| 2021 | 1023 | -33.76 | -0.35 | 438 | 585 | 42.8 | -36.12 | 1h 04m |
Trade charts — best 2 and worst 2 performing pairs (full OHLC candles are expensive to render for every pair)
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.
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
Out-of-sample backtest on recent data · 33 pairs · 20260101-20260701.
Backtest trust check
1 potential lookahead pattern(s) found
| Line | Pattern | Detail | |
|---|---|---|---|
| 189 | leak | iloc_last | iloc[-1] in populate_* applies the newest candle to all rows |
ran by Ron · took s
Lookahead analysis
freqtrade lookahead-analysis: detects strategies peeking at future candles.