💬 Forum

BollingerBandStrategy

🏆 League #1007 / 1937

WKoniczynski/freqtrade_bot/user_data/strategies/bollinger_band_strategy.py · ★1 · first seen 2026-07-16 · repo updated 2026-04-08 · ⬇ 2 downloads

Basics mode: spot timeframe: 5m interface version: 3
Settings stoploss: -0.1
Indicators Bollinger_Bands RSI talib
Concepts mean_reversion
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 →

 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
import talib
from freqtrade.strategy import IStrategy
from pandas import DataFrame


class BollingerBandStrategy(IStrategy):
    """
    Bollinger Band Strategy
    
    Entry: When price crosses below the lower Bollinger Band (oversold)
    Exit: When price crosses above the middle Bollinger Band (mean reversion)
    """

    INTERFACE_VERSION = 3
    
    # Bollinger Bands parameters
    bb_period = 20
    bb_dev = 2.0
    
    # Stoploss
    stoploss = -0.10
    
    # Trailing stop
    trailing_stop = False
    
    # Optimal timeframe
    timeframe = '5m'
    
    # Can short
    can_short = False

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Add technical indicators to the dataframe.
        """
        # Calculate Bollinger Bands
        dataframe['bb_lower'], dataframe['bb_middle'], dataframe['bb_upper'] = talib.BBANDS(
            dataframe['close'], 
            timeperiod=self.bb_period, 
            nbdevup=self.bb_dev, 
            nbdevdn=self.bb_dev
        )
        
        # Optional: RSI for confirmation
        dataframe['rsi'] = talib.RSI(dataframe['close'], timeperiod=14)
        
        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Populate BUY signal for the given dataframe.
        
        Buy when price crosses below lower Bollinger Band AND RSI is oversold.
        """
        dataframe.loc[
            (
                (dataframe['close'] < dataframe['bb_lower']) &
                (dataframe['rsi'] < 30) &  # RSI oversold confirmation
                (dataframe['volume'] > 0)
            ),
            'enter_long'] = 1
            
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Populate SELL signal for the given dataframe.
        
        Sell when price crosses above middle Bollinger Band.
        """
        dataframe.loc[
            (
                (dataframe['close'] > dataframe['bb_middle']) &
                (dataframe['volume'] > 0)
            ),
            'exit_long'] = 1

        return dataframe