0bps

Strategy vault / Breakout

Bollinger Bands Breakout Momentum Trading Strategy

This strategy is a momentum tracking trading system based on Bollinger Bands indicator. It identifies potential breakout opportunities by monitoring the relationship between price and the upper Bollinger Band, and…

Author
ChaoZhang
Complexity
Starter · 51 lines
Parameters
0
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is a momentum tracking trading system based on Bollinger Bands indicator. It identifies potential breakout opportunities by monitoring the relationship between price and the upper Bollinger Band, and closes positions when price breaks below the lower band. Bollinger Bands consist of three lines: the middle band (moving average), upper and lower bands (calculated using standard deviation). The strategy supports multiple types of moving averages and allows parameter adjustment based on trader preferences.

Strategy Principles

The core logic of the strategy is based on the following points:

  1. Entry Signal: When the closing price breaks above the upper Bollinger Band, indicating a potential strong uptrend, a long position is opened.
  2. Exit Signal: When the closing price falls below the lower Bollinger Band, suggesting momentum exhaustion, the position is closed.
  3. Bollinger Bands Calculation: The middle band uses selectable moving average types (SMA, EMA, SMMA, WMA, VWMA), and band width is determined by standard deviation multiplier.
  4. Trade Management: The strategy executes trades within a specified time window, uses 100% capital per trade, and considers commission and slippage factors.

Strategy Advantages

  1. High Adaptability: Supports multiple moving average types and parameter adjustments to adapt to different market conditions.
  2. Robust Risk Management: Effectively controls risk using the lower Bollinger Band as a stop-loss point.
  3. Breakout Confirmation: Uses upper Bollinger Band as entry point to filter false breakouts.
  4. Rational Capital Management: Adopts fixed proportion capital management to avoid excessive leverage.
  5. Transaction Cost Consideration: Incorporates commission and slippage for more realistic trading conditions.

Strategy Risks

  1. Sideways Market Risk: Prone to false signals in range-bound markets.
  2. Lag Risk: Moving averages have inherent lag, potentially missing optimal entry points.
  3. Parameter Sensitivity: Different parameter combinations may lead to significant performance variations.
  4. Capital Usage Risk: 100% capital allocation may result in substantial drawdowns.

Strategy Optimization Directions

  1. Add Trend Confirmation Indicators: Include indicators like ADX to improve entry accuracy.
  2. Optimize Capital Management: Introduce dynamic position sizing based on market volatility.
  3. Enhance Profit-Taking Mechanism: Set dynamic take-profit points to capture more gains in strong trends.
  4. Add Market Environment Filters: Incorporate volatility indicators to avoid trading in unsuitable market conditions.

Summary

This is a trend-following strategy based on Bollinger Bands, capturing market trends by observing the relationship between price and the bands. The strategy is well-designed with good adaptability and risk management mechanisms. Through the suggested optimization directions, the strategy's stability and profitability can be further enhanced. It is particularly suitable for volatile markets, but traders need to adjust parameters and risk control measures according to actual conditions.

Source Pine Script

/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(title="Demo GPT - Bollinger Bands Strategy", overlay=true, initial_capital=100000, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3)

// Inputs
length = input.int(20, minval=1, title="Length")
maType = input.string("SMA", "Basis MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval=-500, maxval=500)
startDate = input(timestamp('01 Jan 2018 00:00 +0000'), title="Start Date")
endDate = input(timestamp('31 Dec 2069 23:59 +0000'), title="End Date")

// Moving Average Function
ma(source, length, _type) =>
    switch _type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

// Calculations
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

// Plotting
plot(basis, "Basis", color=#2962FF, offset=offset)
p1 = plot(upper, "Upper", color=#F23645, offset=offset)
p2 = plot(lower, "Lower", color=#089981, offset=offset)
fill(p1, p2, title="Background", color=color.rgb(33, 150, 243, 95))

// Strategy Logic
inTradeWindow = true
longCondition = close > upper and inTradeWindow
exitCondition = close < lower and inTradeWindow

if (longCondition)
    strategy.entry("Long", strategy.long, qty=1)
if (exitCondition)
    strategy.close("Long")

Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-06. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Bollinger-Bands-Breakout-Momentum-Trading-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open