💬 Forum

BreakoutStrategy

🏆 League #1653 / 1939

jinzheng8115/freqtrade-crypto-system/user_data/strategies/BreakoutStrategy.py · first seen 2026-07-16 · repo updated 2026-02-23

Basics mode: spot timeframe: 15m interface version: 3
Settings stoploss: -0.05 has minimal roi trailing startup candle count: 100 hyperopt hyperopt params: 1
Indicators ATR talib
Concepts breakout trailing
15 related strategies ( identical code, similar name)

Each tile is a different kind of check — from an instant code lint to full sandboxed backtests and forward tests on recent data. Not sure what a check actually proves? See the FAQ →

Source

Download Raw
 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
# 突破策略 - Donchian Channel
# 原理:价格突破 N 日高点买入,跌破 N 日低点卖出
# 适合:趋势市场
from freqtrade.strategy import IStrategy, IntParameter
from pandas import DataFrame
import talib.abstract as ta
from functools import reduce

class BreakoutStrategy(IStrategy):
    INTERFACE_VERSION = 3
    
    # 突破周期
    breakout_period = IntParameter(10, 30, default=20, space="buy", optimize=True)
    
    minimal_roi = {"0": 0.10}
    stoploss = -0.05
    
    timeframe = '15m'
    
    trailing_stop = True
    trailing_stop_positive = 0.03
    trailing_stop_positive_offset = 0.04
    
    startup_candle_count = 100
    
    order_types = {
        'entry': 'limit',
        'exit': 'limit',
        'stoploss': 'market',
        'stoploss_on_exchange': False
    }
    
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        period = self.breakout_period.value
        
        # Donchian Channel
        dataframe['don_high'] = dataframe['high'].rolling(period).max()
        dataframe['don_low'] = dataframe['low'].rolling(period).min()
        dataframe['don_mid'] = (dataframe['don_high'] + dataframe['don_low']) / 2
        
        # ATR
        dataframe['atr'] = ta.ATR(dataframe, timeperiod=14)
        
        # Volume
        dataframe['volume_ma'] = dataframe['volume'].rolling(20).mean()
        
        return dataframe
    
    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[:, 'enter_long'] = 0
        
        conditions = [
            # 价格突破上轨
            dataframe['close'] > dataframe['don_high'].shift(1),
            # 成交量确认
            dataframe['volume'] > dataframe['volume_ma'],
        ]
        
        if conditions:
            dataframe.loc[reduce(lambda x, y: x & y, conditions), 'enter_long'] = 1
        
        return dataframe
    
    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[:, 'exit_long'] = 0
        
        conditions = [
            # 价格跌破下轨
            dataframe['close'] < dataframe['don_low'].shift(1),
        ]
        
        if conditions:
            dataframe.loc[reduce(lambda x, y: x & y, conditions), 'exit_long'] = 1
        
        return dataframe