💬 Forum

BollingerBreakoutStrategy

🏆 League #1396 / 1937

DonaldSimpson/remora-backtests/strategies/BollingerBreakoutStrategy.py · ★5 · ⑂1 · first seen 2026-07-16 · repo updated 2025-12-22

Basics mode: spot timeframe: 5m interface version: 3
Settings stoploss: -0.1 has minimal roi process only new candles: false startup candle count: 200
Indicators Bollinger_Bands RSI SMA talib
Concepts breakout 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 →

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
 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
"""
Bollinger Breakout Strategy

A strategy based on Bollinger Bands for breakout trading.
Entry: When price breaks above upper Bollinger Band
Exit: When price returns to middle band or profit target reached
"""

# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
# flake8: noqa: F401
# isort: skip_file

import numpy as np
import pandas as pd
from pandas import DataFrame
from typing import Optional
import talib.abstract as ta
from freqtrade.strategy import IStrategy


class BollingerBreakoutStrategy(IStrategy):
    """
    Bollinger Breakout Strategy
    
    Uses Bollinger Bands to identify breakouts.
    """
    
    INTERFACE_VERSION = 3
    timeframe = '5m'
    can_short: bool = False
    
    # ROI table
    minimal_roi = {
        "0": 0.10,   # 10% profit target
        "60": 0.05,  # 5% after 60 minutes
        "120": 0.02  # 2% after 120 minutes
    }
    
    stoploss = -0.10  # 10% stop loss
    trailing_stop = False
    
    process_only_new_candles = False
    use_exit_signal = True
    exit_profit_only = False
    ignore_roi_if_entry_signal = False
    startup_candle_count: int = 200
    
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Add indicators to the dataframe.
        
        Args:
            dataframe: DataFrame with OHLCV data
            metadata: Pair metadata
            
        Returns:
            DataFrame with indicators added
        """
        # Bollinger Bands
        bollinger = ta.BBANDS(dataframe, timeperiod=20, nbdevup=2.0, nbdevdn=2.0)
        dataframe['bb_upper'] = bollinger['upperband']
        dataframe['bb_middle'] = bollinger['middleband']
        dataframe['bb_lower'] = bollinger['lowerband']
        
        # RSI for confirmation
        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
        
        # Volume SMA
        dataframe['volume_sma'] = ta.SMA(dataframe['volume'], timeperiod=20)
        
        # Price position within bands
        dataframe['bb_percent'] = (
            (dataframe['close'] - dataframe['bb_lower']) /
            (dataframe['bb_upper'] - dataframe['bb_lower'])
        )
        
        return dataframe
    
    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Populate entry signals.
        
        Entry when:
        - Price breaks above upper Bollinger Band
        - RSI is strong but not overbought (50-75)
        - Volume is above average
        """
        dataframe.loc[
            (
                (dataframe['close'] > dataframe['bb_upper']) &
                (dataframe['close'].shift(1) <= dataframe['bb_upper'].shift(1)) &
                (dataframe['rsi'] > 50) &
                (dataframe['rsi'] < 75) &
                (dataframe['volume'] > dataframe['volume_sma'] * 0.9) &
                (dataframe['bb_percent'] > 1.0)  # Above upper band
            ),
            'enter_long'
        ] = 1
        
        return dataframe
    
    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Populate exit signals.
        
        Exit when:
        - Price returns to middle band
        - RSI becomes overbought (> 80)
        """
        dataframe.loc[
            (
                (dataframe['close'] < dataframe['bb_middle']) &
                (dataframe['close'].shift(1) >= dataframe['bb_middle'].shift(1))
            ) |
            (dataframe['rsi'] > 80),
            'exit_long'
        ] = 1
        
        return dataframe