0bps

Strategy vault / Breakout

Bollinger Bands Dynamic Breakout Strategy

The Dynamic Bollinger Bands Breakout Strategy is a trading strategy based on the Bollinger Bands indicator. This strategy uses the upper and lower bands of the Bollinger Bands as dynamic support and resistance…

Author
ChaoZhang
Complexity
Starter · 40 lines
Parameters
0
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG

Overview

The Dynamic Bollinger Bands Breakout Strategy is a trading strategy based on the Bollinger Bands indicator. This strategy uses the upper and lower bands of the Bollinger Bands as dynamic support and resistance levels, buying when the price breaks above the upper band and selling when it breaks below the lower band. Bollinger Bands consist of a middle band (moving average), an upper band (middle band plus a multiple of standard deviation), and a lower band (middle band minus a multiple of standard deviation), which can be dynamically adjusted to adapt to market volatility.

Strategy Principle

  1. Calculate the middle, upper, and lower bands of the Bollinger Bands. The middle band is the simple moving average of the closing price, the upper band is the middle band plus a multiple of the standard deviation, and the lower band is the middle band minus a multiple of the standard deviation.
  2. When the price crosses above the upper band, open a long position; when the price crosses below the lower band, open a short position.
  3. When a long position exists, if the price crosses below the upper band, close the long position; when a short position exists, if the price crosses above the lower band, close the short position.

Strategy Advantages

  1. Bollinger Bands can dynamically adjust to adapt to different market volatility conditions, providing a certain degree of adaptability.
  2. The strategy logic is clear and easy to understand and implement.
  3. Bollinger Bands perform well when the market trend is strong and can effectively capture trends.

Strategy Risks

  1. In situations where market volatility is high and the trend is choppy, this strategy may frequently trade, leading to increased transaction costs.
  2. The selection of Bollinger Bands parameters (such as the moving average period and standard deviation multiple) will affect the strategy's performance, and different parameters may bring different results.
  3. This strategy does not consider other technical indicators or fundamental factors and relies solely on the relationship between price and Bollinger Bands for trading decisions, which may face risks brought by a single signal.

Strategy Optimization Directions

  1. Introduce other technical indicators (such as RSI, MACD, etc.) as filtering conditions to confirm the validity of Bollinger Band breakouts and improve signal quality.
  2. Optimize Bollinger Bands parameters by backtesting and parameter scanning to find the best combination of moving average period and standard deviation multiple.
  3. Set appropriate stop-loss and take-profit levels to control single transaction risk and profit targets.
  4. Consider market conditions and volatility, dynamically adjusting strategy parameters or position sizes under different market conditions.

Summary

The Dynamic Bollinger Bands Breakout Strategy is a simple and easy-to-use trading strategy that generates trading signals through breakouts of the upper and lower bands of the Bollinger Bands. This strategy performs well in trending markets but may face frequent trading issues in choppy markets. Optimization directions include combining other technical indicators, optimizing parameters, setting appropriate stop-losses and take-profits, and adjusting strategies according to market conditions. In practical applications, it is necessary to make appropriate adjustments and optimizations based on specific market characteristics and personal risk preferences.

Source Pine Script

/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Bollinger Bands with Strategy", shorttitle='MBB', overlay=true)

// Input Variables
src = close
length = input.int(34, "Length", minval=1)
mult = input.float(2.0, "Multiplier", minval=0.001, maxval=50)

// Bollinger Bands Calculation
basis = ta.sma(src, length)
dev = ta.stdev(src, length)
upperBand = basis + mult * dev
lowerBand = basis - mult * dev

// Plotting Bollinger Bands
pBasis = plot(basis, "Basis", color=color.gray)
pUpper = plot(upperBand, "Upper Band", color=color.green)
pLower = plot(lowerBand, "Lower Band", color=color.red)
fill(pUpper, pBasis, color=color.new(color.green, 90))
fill(pBasis, pLower, color=color.new(color.red, 90))

// Strategy Execution Using `if`
if (ta.crossover(src, upperBand))
    strategy.entry("Long", strategy.long)
if (ta.crossunder(src, lowerBand))
    strategy.entry("Short", strategy.short)

if (ta.crossunder(src, upperBand))
    strategy.close("Long")
if (ta.crossover(src, lowerBand))
    strategy.close("Short")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-05-15. 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-Dynamic-Breakout-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