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 | # -*- coding: utf-8 -*- # Source: day17.md - BrooksPriceActionStrategy # Freqtrade 21 天从入门到精通 from freqtrade.strategy import IStrategy from pandas import DataFrame import numpy as np class BrooksPriceActionStrategy(IStrategy): """ Al Brooks 价格行为策略 核心逻辑: 1. 判断市场状态(趋势/区间/反转) 2. 趋势中:等待回调,用二次入场做多/做空 3. 区间中:在边界做反向交易 4. 反转时:识别楔形和强反转 K 线 参考:Al Brooks "Trading Price Action" 三部曲 """ INTERFACE_VERSION = 3 minimal_roi = {"0": 0.08, "30": 0.04, "60": 0.02} stoploss = -0.05 trailing_stop = True trailing_stop_positive = 0.01 trailing_stop_positive_offset = 0.03 timeframe = '1h' def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # K 线属性 range_ = dataframe['high'] - dataframe['low'] range_ = range_.replace(0, 1e-8) body = abs(dataframe['close'] - dataframe['open']) dataframe['body_ratio'] = body / range_ dataframe['close_position'] = (dataframe['close'] - dataframe['low']) / range_ dataframe['upper_wick'] = np.where( dataframe['close'] >= dataframe['open'], (dataframe['high'] - dataframe['close']) / range_, (dataframe['high'] - dataframe['open']) / range_ ) dataframe['lower_wick'] = np.where( dataframe['close'] >= dataframe['open'], (dataframe['open'] - dataframe['low']) / range_, (dataframe['close'] - dataframe['low']) / range_ ) # 市场状态判断 dataframe['ema_20'] = dataframe['close'].ewm(span=20).mean() dataframe['ema_slope'] = dataframe['ema_20'].diff(5) / dataframe['ema_20'].shift(5) # 连续同向 K 线计数 dataframe['bull_bar'] = (dataframe['close'] > dataframe['open']).astype(int) dataframe['bear_bar'] = (dataframe['close'] < dataframe['open']).astype(int) dataframe['consec_bull'] = dataframe['bull_bar'].groupby( (dataframe['bull_bar'] != dataframe['bull_bar'].shift()).cumsum() ).cumsum() dataframe['consec_bear'] = dataframe['bear_bar'].groupby( (dataframe['bear_bar'] != dataframe['bear_bar'].shift()).cumsum() ).cumsum() dataframe['trend_strength'] = dataframe['ema_slope'].rolling(10).mean() # 信号 K 线 dataframe['bull_signal'] = ( (dataframe['close_position'] > 0.6) & (dataframe['lower_wick'] > 0.3) & (dataframe['body_ratio'] > 0.25) & (dataframe['close'] > dataframe['open']) ).astype(int) dataframe['bear_signal'] = ( (dataframe['close_position'] < 0.4) & (dataframe['upper_wick'] > 0.3) & (dataframe['body_ratio'] > 0.25) & (dataframe['close'] < dataframe['open']) ).astype(int) # 二次入场检测 dataframe['recent_bull_signals'] = dataframe['bull_signal'].rolling(10).sum() dataframe['second_entry_bull'] = ( (dataframe['bull_signal'] == 1) & (dataframe['recent_bull_signals'] >= 2) ).astype(int) dataframe['recent_bear_signals'] = dataframe['bear_signal'].rolling(10).sum() dataframe['second_entry_bear'] = ( (dataframe['bear_signal'] == 1) & (dataframe['recent_bear_signals'] >= 2) ).astype(int) # 楔形检测(简化) dataframe['is_swing_low'] = ( (dataframe['low'] < dataframe['low'].shift(1)) & (dataframe['low'] < dataframe['low'].shift(-1)) & (dataframe['low'] < dataframe['low'].shift(2)) & (dataframe['low'] < dataframe['low'].shift(-2)) ).astype(int) dataframe['swing_low_count'] = dataframe['is_swing_low'].rolling(30).sum() dataframe['price_declining'] = (dataframe['low'] < dataframe['low'].rolling(30).mean()).astype(int) dataframe['wedge_bull'] = ( (dataframe['swing_low_count'] >= 3) & (dataframe['price_declining'] == 1) & (dataframe['bull_signal'] == 1) ).astype(int) # 支撑阻力 dataframe['resistance'] = dataframe['high'].rolling(20).max() dataframe['support'] = dataframe['low'].rolling(20).min() dataframe['range_width'] = (dataframe['resistance'] - dataframe['support']) / dataframe['close'] dataframe['range_position'] = ( (dataframe['close'] - dataframe['support']) / (dataframe['resistance'] - dataframe['support'] + 1e-8) ) return dataframe def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # 策略 1:趋势中的二次入场 dataframe.loc[ ( (dataframe['second_entry_bull'] == 1) & (dataframe['trend_strength'] > 0.001) & (dataframe['close'] > dataframe['ema_20']) & (dataframe['volume'] > 0) ), ['enter_long', 'enter_tag'] ] = (1, 'brooks_2nd_entry') # 策略 2:楔形反转 dataframe.loc[ ( (dataframe['wedge_bull'] == 1) & (dataframe['range_position'] < 0.3) & (dataframe['volume'] > 0) & (dataframe['enter_long'] != 1) ), ['enter_long', 'enter_tag'] ] = (1, 'brooks_wedge') # 策略 3:区间底部反弹 dataframe.loc[ ( (dataframe['range_position'] < 0.15) & (dataframe['bull_signal'] == 1) & (dataframe['range_width'] > 0.03) & (dataframe['volume'] > 0) & (dataframe['enter_long'] != 1) ), ['enter_long', 'enter_tag'] ] = (1, 'brooks_range_bottom') return dataframe def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe.loc[ ( (dataframe['bear_signal'] == 1) & (dataframe['range_position'] > 0.85) ) | ( (dataframe['consec_bear'] >= 3) & (dataframe['trend_strength'] < -0.002) ), 'exit_long' ] = 1 return dataframe |
Strategy League — fixed backtest that feeds the ranking
Export report Freqtrade logsRun finished · took 45.9s
ℹ️ This strategy uses a trailing stop — freqtrade only
re-checks these once per 1h candle by default, not against the price movement within it.
For a more accurate read, re-run this backtest locally with --timeframe-detail 1m
(or 5m — freqtrade's own docs use 5m detail for an hourly strategy as a lighter
alternative). 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 0% of rolling 3-month windows
- did not beat simply holding the market
- very deep drawdown (-90%)
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 |
|---|---|---|---|---|---|---|---|---|---|
| May 2021 | bearish trending high vol | 123 | -13.12 | -1.07 | 50 | 73 | 40.7 | -90.12 | 3h 32m |
| Apr 2021 | bearish choppy high vol | 236 | -6.92 | -0.29 | 127 | 109 | 53.8 | -79.68 | 4h 35m |
| Mar 2021 | bullish choppy high vol | 232 | -7.79 | -0.34 | 122 | 110 | 52.6 | -72.14 | 6h 20m |
| Feb 2021 | bullish trending high vol | 415 | -13.27 | -0.32 | 222 | 193 | 53.5 | -62.98 | 3h 27m |
| Jan 2021 | bullish trending high vol | 573 | -48.98 | -0.85 | 250 | 323 | 43.6 | -49.16 | 3h 13m |
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
2 potential lookahead pattern(s) found · 1 to review
| Line | Pattern | Detail | |
|---|---|---|---|
| 102 | leak | negative_shift | shift() with negative periods reads future candles |
| 100 | |||
| 127 | review | enter_tag_overwrite | enter_tag/exit_tag is written by 3 separate assignments -- they share one column and run in source order, so a row matching more than one condition keeps only the LAST tag. Per-tag statistics won't mean what they appear to |
ran by Ron · took s
Lookahead analysis
freqtrade lookahead-analysis: detects strategies peeking at future candles.