Basics
mode: spot
timeframe: 1h
interface version: 3
Settings
stoploss: -0.25
has minimal roi
dca
startup candle count: 50
hyperopt
hyperopt params: 4
Indicators
ADX
ATR
Bollinger_Bands
EMA
RSI
talib
Concepts
dca
grid
Methods
adjust_trade_entry
custom_exit
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 | import talib.abstract as ta from pandas import DataFrame from freqtrade.strategy import IStrategy, DecimalParameter, IntParameter from freqtrade.persistence import Trade import logging logger = logging.getLogger(__name__) class GridStrategy(IStrategy): """ 专业自适应网格策略 核心改进(相比交易所内置网格): 1. ATR 动态间距:波动大 → 格子自动拉宽,避免过早加仓;波动小 → 格子收窄,提高资金效率 2. ADX 趋势过滤:ADX > 阈值说明是趋势市,不开新仓;只在震荡市运行 3. 递增仓位:第1次加仓1倍,第2次1.5倍,第3次2倍 → 越跌买越多,更快摊低均价 4. ATR 动态止盈:回升 N×ATR 就出场,不用死板的固定百分比 5. EMA200 趋势方向:只在大方向向上时做多,避免逆势抄底 """ INTERFACE_VERSION = 3 timeframe = "1h" can_short = False position_adjustment_enable = True max_entry_position_adjustment = 4 # 最多加仓4次(共5档) # ROI 设宽,主要由 custom_exit 控制精确出场 minimal_roi = { "0": 0.10, "2880": 0.02, # 持仓 120 天还没涨,降到 2% 接受出场 "5760": 0.005, } # 止损设宽:覆盖5档×ATR的加仓空间 stoploss = -0.25 trailing_stop = False startup_candle_count = 50 # ── Hyperopt 参数 ──────────────────────────────────────────────── # 网格间距倍数(间距 = atr_mult × ATR) atr_mult = DecimalParameter(0.5, 2.5, default=1.2, decimals=1, space="buy") # ADX 阈值:低于此值认为是震荡市,才允许入场 adx_max = IntParameter(15, 40, default=28, space="buy") # 布林带宽度上限:太宽说明正在剧烈波动,不入场 bb_width_max = DecimalParameter(0.04, 0.20, default=0.10, decimals=2, space="buy") # 止盈触发:均价回升 tp_atr_mult × ATR 就出场 tp_atr_mult = DecimalParameter(0.5, 2.0, default=1.0, decimals=1, space="sell") # ATR 缓存:populate_indicators 中更新,custom_exit/adjust_entry 中读取 _atr_cache: dict = {} # ── 指标计算 ───────────────────────────────────────────────────── def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe["atr"] = ta.ATR(dataframe, timeperiod=14) dataframe["adx"] = ta.ADX(dataframe, timeperiod=14) dataframe["ema200"] = ta.EMA(dataframe, timeperiod=200) dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14) upper, mid, lower = ta.BBANDS(dataframe["close"], timeperiod=20, nbdevup=2.0, nbdevdn=2.0) dataframe["bb_upper"] = upper dataframe["bb_mid"] = mid dataframe["bb_lower"] = lower # BB宽度归一化((上轨-下轨)/中轨),代表相对波动幅度 dataframe["bb_width"] = (upper - lower) / mid # 缓存最新 ATR,供 custom_exit 和 adjust_trade_entry 使用 if len(dataframe) > 0: self._atr_cache[metadata["pair"]] = float(dataframe["atr"].iloc[-1]) return dataframe # ── 入场信号 ───────────────────────────────────────────────────── def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe.loc[ ( # 大方向:价格在 EMA200 之上(长期上升趋势) (dataframe["close"] > dataframe["ema200"]) & # 趋势强度低:ADX 小 → 震荡市,适合网格 (dataframe["adx"] < self.adx_max.value) & # 波动幅度不过大:BB 宽度在合理范围内 (dataframe["bb_width"] < self.bb_width_max.value) & # 入场位置:价格不高于 BB 中轨太多(不在高位追入) (dataframe["close"] <= dataframe["bb_mid"] * 1.01) & # 成交量有效 (dataframe["volume"] > 0) ), "enter_long", ] = 1 return dataframe def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # 不设退出信号,全部由 custom_exit + minimal_roi 控制 return dataframe # ── 动态止盈 ───────────────────────────────────────────────────── FEE_RATE = 0.001 # OKX 现货挂单费率 0.10% def custom_exit(self, pair, trade, current_time, current_rate, current_profit, **kwargs): """ 均价回升 tp_atr_mult × ATR 时止盈出场。 最小止盈随 DCA 档数动态提高,确保每笔交易扣完手续费后都真正盈利。 """ atr = self._atr_cache.get(pair) if atr is None or trade.open_rate == 0: return None filled = trade.nr_of_successful_entries # DCA 每加一档多一笔入场手续费;最小止盈 = 累计入场费 + 0.2% 净利缓冲 fee_buffer = self.FEE_RATE * filled + 0.002 atr_target = (self.tp_atr_mult.value * atr) / trade.open_rate profit_target = max(atr_target, fee_buffer) if current_profit >= profit_target: filled = trade.nr_of_successful_entries return f"grid_tp_lvl{filled}_{current_profit:.3f}" return None # ── 网格加仓逻辑 ───────────────────────────────────────────────── def adjust_trade_entry( self, trade: Trade, current_time, current_rate: float, current_profit: float, min_stake, max_stake: float, current_entry_rate: float, current_exit_rate: float, current_entry_profit: float, current_exit_profit: float, **kwargs, ): """ 自适应网格加仓: - 间距 = atr_mult × ATR(随市场波动自动调整) - 仓位递增:填入第N档时,加仓 = 初始仓 × (1 + (N-1)×0.5) 档位 加仓倍数 资金比例 1 1.0× 第1次同等金额 2 1.5× 价格再跌一格 3 2.0× ... 4 2.5× 第4次加仓 """ filled = trade.nr_of_successful_entries if filled >= (self.max_entry_position_adjustment + 1): return None # 动态间距:ATR占当前价的比例 atr = self._atr_cache.get(trade.pair) if atr: grid_step = (self.atr_mult.value * atr) / current_rate grid_step = max(grid_step, 0.01) # 最小1% grid_step = min(grid_step, 0.08) # 最大8%(防极端行情) else: grid_step = 0.025 # 无ATR时降级到2.5%固定间距 # 达到触发阈值才加仓 threshold = -(grid_step * filled) if current_profit > threshold: return None # 递增仓位:第1档加1倍,第2档加1.5倍,依此类推 multiplier = 1.0 + max(filled - 1, 0) * 0.5 stake = trade.stake_amount * multiplier stake = max(stake, min_stake or 0) stake = min(stake, max_stake) logger.info( f"[Grid] {trade.pair} 第{filled}次加仓 | " f"间距={grid_step:.2%} 阈值={threshold:.2%} 当前={current_profit:.2%} | " f"加仓={stake:.2f} USDT ({multiplier}x)" ) return stake |
Strategy League — fixed backtest that feeds the ranking
Export report Freqtrade logsRun finished · took 100.4s
pairs 33 pairs
timerange 20210101-20260101
mode spot
timeframe 1h
stake 100 USDT
wallet 1000 USDT
max open trades 10
fee exchange lowest tier
total profit-72.91%
final wallet271 USDT
win rate94.2%
max drawdown-84.86%
market change+447.62%
vs market-520.53%
timeframe1h
profit factor0.88
expectancy ratio-0.007
break-even fee0.015%
sharpe-1.216
sortino-7.248
CAGR-23.0%
calmar-0.899
avg MFE+2.69%
avg MAE-4.63%
avg profit/trade-0.17%
avg duration52h 14m
best trade+10.04%
worst trade-25.15%
win/loss streak338 / 10
DCA orders0 max / 0.0 avg
max stake exposure100.0 USDT (1.0x base)
positive months26/61
consistent (3-mo)39.0%
worst 3-mo-58.25%
trades4296
revision1
likely annual return-23%
range (5th–95th)-36% … -8%
chance of profit1.1%
worst-5% outcome-40%
significance (p)0.965
risk of ruin0.0%
- profit isn't statistically significant (p=0.96) — hard to tell apart from luck
- only 1% of resampled runs were profitable
- profitable in only 39% of rolling 3-month windows
- did not beat simply holding the market
- very deep drawdown (-85%)
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 |
|---|---|---|---|---|---|---|---|---|---|
| Jan 2026 | bullish trending low vol | 2 | -2.68 | -13.42 | 0 | 2 | 0.0 | -84.86 | 1476h 00m |
| Dec 2025 | bearish trending low vol | 1 | -2.52 | -25.15 | 0 | 1 | 0.0 | -83.36 | 291h 00m |
| Nov 2025 | bearish trending high vol | 6 | -4.25 | -7.12 | 4 | 2 | 66.7 | -82.14 | 247h 10m |
| Oct 2025 | bearish trending low vol | 27 | -8.52 | -3.17 | 23 | 4 | 85.2 | -79.59 | 108h 56m |
| Sep 2025 | bullish choppy low vol | 33 | +2.53 | 0.77 | 33 | 0 | 100.0 | -76.2 | 75h 35m |
| Aug 2025 | bullish choppy low vol | 35 | +2.77 | 0.79 | 35 | 0 | 100.0 | -77.75 | 48h 10m |
| Jul 2025 | bullish choppy low vol | 55 | +5.34 | 0.97 | 55 | 0 | 100.0 | -80.66 | 63h 37m |
| Jun 2025 | bearish choppy low vol | 10 | -1.02 | -1.02 | 9 | 1 | 90.0 | -81.59 | 119h 00m |
| May 2025 | bullish trending low vol | 36 | +2.82 | 0.78 | 36 | 0 | 100.0 | -81.71 | 37h 35m |
| Apr 2025 | bullish choppy low vol | 37 | -1.50 | -0.40 | 35 | 2 | 94.6 | -83.74 | 60h 47m |
| Mar 2025 | bearish trending high vol | 49 | -5.04 | -1.03 | 45 | 4 | 91.8 | -82.56 | 29h 20m |
| Feb 2025 | bearish trending low vol | 42 | -16.66 | -3.97 | 34 | 8 | 81.0 | -78.11 | 83h 03m |
| Jan 2025 | bearish choppy low vol | 63 | -4.26 | -0.68 | 59 | 4 | 93.7 | -69.14 | 59h 39m |
| Dec 2024 | bullish trending low vol | 93 | -3.10 | -0.33 | 88 | 5 | 94.6 | -66.7 | 28h 45m |
| Nov 2024 | bullish trending low vol | 146 | +17.78 | 1.22 | 146 | 0 | 100.0 | -74.59 | 37h 09m |
| Oct 2024 | bullish choppy low vol | 15 | +1.13 | 0.75 | 15 | 0 | 100.0 | -75.22 | 102h 20m |
| Sep 2024 | bearish choppy low vol | 22 | +2.03 | 0.92 | 22 | 0 | 100.0 | -76.36 | 113h 00m |
| Aug 2024 | bearish choppy high vol | 28 | -12.77 | -4.56 | 22 | 6 | 78.6 | -77.56 | 91h 19m |
| Jul 2024 | bearish trending low vol | 78 | -4.88 | -0.63 | 73 | 5 | 93.6 | -73.42 | 89h 18m |
| Jun 2024 | bearish choppy low vol | 7 | -4.61 | -6.59 | 5 | 2 | 71.4 | -66.72 | 622h 26m |
| May 2024 | bullish choppy high vol | 19 | +2.26 | 1.19 | 19 | 0 | 100.0 | -65.17 | 98h 25m |
| Apr 2024 | bearish choppy high vol | 39 | -14.17 | -3.63 | 32 | 7 | 82.1 | -66.96 | 110h 02m |
| Mar 2024 | bullish trending high vol | 95 | +7.48 | 0.79 | 93 | 2 | 97.9 | -61.37 | 60h 05m |
| Feb 2024 | bullish trending low vol | 57 | +6.75 | 1.18 | 57 | 0 | 100.0 | -65.2 | 82h 57m |
| Jan 2024 | bearish choppy high vol | 28 | +0.45 | 0.16 | 27 | 1 | 96.4 | -66.61 | 101h 21m |
| Dec 2023 | bullish trending low vol | 49 | +5.22 | 1.07 | 49 | 0 | 100.0 | -68.37 | 62h 01m |
| Nov 2023 | bullish trending low vol | 52 | +8.56 | 1.65 | 52 | 0 | 100.0 | -73.16 | 116h 50m |
| Oct 2023 | bullish trending low vol | 14 | +3.26 | 2.33 | 14 | 0 | 100.0 | -74.98 | 294h 56m |
| Sep 2023 | bearish choppy low vol | 2 | -2.30 | -11.51 | 1 | 1 | 50.0 | -75.12 | 254h 30m |
| Aug 2023 | bearish choppy low vol | 9 | -6.40 | -7.11 | 6 | 3 | 66.7 | -74.36 | 511h 40m |
| Jul 2023 | bullish trending low vol | 22 | +4.30 | 1.95 | 22 | 0 | 100.0 | -72.46 | 90h 57m |
| Jun 2023 | bullish trending low vol | 13 | -3.28 | -2.52 | 11 | 2 | 84.6 | -73.37 | 328h 42m |
| May 2023 | bearish choppy low vol | 5 | -2.27 | -4.53 | 4 | 1 | 80.0 | -70.85 | 468h 12m |
| Apr 2023 | bullish trending low vol | 8 | +0.91 | 1.13 | 8 | 0 | 100.0 | -69.92 | 245h 52m |
| Mar 2023 | bullish trending high vol | 31 | -0.54 | -0.17 | 29 | 2 | 93.5 | -72.46 | 146h 08m |
| Feb 2023 | bullish trending low vol | 14 | +1.60 | 1.14 | 14 | 0 | 100.0 | -70.52 | 108h 00m |
| Jan 2023 | bullish trending low vol | 52 | +8.92 | 1.72 | 52 | 0 | 100.0 | -75.51 | 79h 59m |
| Dec 2022 | bearish trending low vol | 13 | -6.75 | -5.19 | 10 | 3 | 76.9 | -75.63 | 178h 09m |
| Nov 2022 | bearish trending high vol | 41 | -6.02 | -1.47 | 36 | 5 | 87.8 | -73.86 | 60h 25m |
| Oct 2022 | bullish choppy low vol | 24 | -1.25 | -0.52 | 22 | 2 | 91.7 | -69.84 | 218h 48m |
| Sep 2022 | bearish choppy high vol | 21 | -2.19 | -1.04 | 19 | 2 | 90.5 | -68.78 | 149h 14m |
| Aug 2022 | bullish choppy high vol | 34 | -4.72 | -1.39 | 30 | 4 | 88.2 | -66.88 | 98h 34m |
| Jul 2022 | bearish trending high vol | 51 | +8.72 | 1.71 | 51 | 0 | 100.0 | -68.68 | 62h 18m |
| Jun 2022 | bearish trending high vol | 55 | -8.59 | -1.56 | 48 | 7 | 87.3 | -72.08 | 48h 15m |
| May 2022 | bearish trending high vol | 45 | -6.81 | -1.51 | 40 | 5 | 88.9 | -66.06 | 74h 41m |
| Apr 2022 | bearish choppy high vol | 41 | -17.00 | -4.14 | 33 | 8 | 80.5 | -60.1 | 95h 26m |
| Mar 2022 | bullish choppy high vol | 116 | +14.94 | 1.29 | 116 | 0 | 100.0 | -58.86 | 47h 05m |
| Feb 2022 | bearish trending high vol | 91 | -8.29 | -0.91 | 83 | 8 | 91.2 | -60.32 | 45h 08m |
| Jan 2022 | bearish trending high vol | 91 | -38.29 | -4.21 | 72 | 19 | 79.1 | -54.97 | 75h 08m |
| Dec 2021 | bearish trending high vol | 111 | -11.67 | -1.05 | 102 | 9 | 91.9 | -38.28 | 38h 32m |
| Nov 2021 | bullish trending high vol | 144 | -6.94 | -0.48 | 136 | 8 | 94.4 | -27.0 | 45h 38m |
| Oct 2021 | bullish trending high vol | 140 | +12.12 | 0.87 | 139 | 1 | 99.3 | -29.26 | 50h 15m |
| Sep 2021 | bearish trending high vol | 147 | -25.72 | -1.75 | 130 | 17 | 88.4 | -29.38 | 36h 49m |
| Aug 2021 | bullish trending high vol | 280 | +34.45 | 1.23 | 279 | 1 | 99.6 | -34.12 | 17h 22m |
| Jul 2021 | bearish trending high vol | 183 | -0.21 | -0.01 | 173 | 10 | 94.5 | -44.68 | 34h 03m |
| Jun 2021 | bearish trending high vol | 133 | -27.59 | -2.08 | 116 | 17 | 87.2 | -35.86 | 32h 33m |
| May 2021 | bearish trending high vol | 175 | -21.87 | -1.25 | 158 | 17 | 90.3 | -18.79 | 24h 15m |
| Apr 2021 | bearish choppy high vol | 323 | +17.53 | 0.54 | 312 | 11 | 96.6 | -12.47 | 20h 33m |
| Mar 2021 | bullish choppy high vol | 173 | +19.77 | 1.14 | 171 | 2 | 98.8 | -14.73 | 34h 17m |
| Feb 2021 | bullish trending high vol | 369 | +21.34 | 0.58 | 353 | 16 | 95.7 | -16.56 | 13h 21m |
| Jan 2021 | bullish trending high vol | 201 | +8.83 | 0.44 | 190 | 11 | 94.5 | -17.98 | 22h 18m |
Yearly breakdown
| Year | Trades | Profit % | Avg % | Win | Loss | Win % | DD % | Avg dur |
|---|---|---|---|---|---|---|---|---|
| 2026 | 2 | -2.68 | -13.42 | 0 | 2 | 0.0 | -84.86 | 1476h 00m |
| 2025 | 394 | -30.31 | -0.77 | 368 | 26 | 93.4 | -83.74 | 65h 40m |
| 2024 | 627 | -1.65 | -0.03 | 599 | 28 | 95.5 | -77.56 | 72h 28m |
| 2023 | 271 | +17.98 | 0.67 | 262 | 9 | 96.7 | -75.51 | 144h 26m |
| 2022 | 623 | -76.25 | -1.22 | 560 | 63 | 89.9 | -75.63 | 73h 54m |
| 2021 | 2379 | +20.04 | 0.08 | 2259 | 120 | 95.0 | -44.68 | 27h 18m |
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 · 1 to review
| Line | Pattern | Detail | |
|---|---|---|---|
| 74 | leak | iloc_last | iloc[-1] in populate_* applies the newest candle to all rows |
| 39 | review | startup_candles_too_small | startup_candle_count is 50, but EMA(timeperiod=200) needs at least 200 candles -- so the first 150+ candles of every backtest use an indicator that hasn't warmed up. Recursive indicators (EMA/RSI/ADX/ATR) want several times their period, not exactly it |
ran by Ron · took s
Lookahead analysis
freqtrade lookahead-analysis: detects strategies peeking at future candles.