0bps

Strategy vault / Breakout

Double Bollinger Bands Breakout Strategy

The Double Bollinger Bands Breakout strategy is a trend following strategy. It uses the upper and lower bands of Bollinger Bands to judge price trends and establish long positions when prices break through the inner…

Author
ChaoZhang
Complexity
Intermediate · 48 lines
Parameters
7
Backtest bar
15m · intraday
Tested on
BTC/USDT · futures

IMG

Overview

The Double Bollinger Bands Breakout strategy is a trend following strategy. It uses the upper and lower bands of Bollinger Bands to judge price trends and establish long positions when prices break through the inner Bollinger Bands and close positions when prices fall below the outer Bollinger Bands.

Strategy Logic

The strategy first calculates the moving average and standard deviation over a specified period. It then constructs the double Bollinger Bands using the moving average ± one standard deviation for the inner bands and the moving average ± 1.5 standard deviations for the outer bands.

When prices break above the upper inner band, it indicates that the market is starting a bull run so goes long. When prices fall below the lower inner band, it indicates the start of a bear market so goes short.

The profit taking exit for long positions is when prices fall below the lower outer band. The profit taking exit for short positions is when prices break above the upper outer band.

The strategy also sets stop loss, take profit and trailing stop loss exits.

Advantage Analysis

The Double Bollinger Bands Breakout strategy has the following advantages:

  1. Using double Bollinger Bands to judge price moves allows effective trend following;
  2. Entering on inner band breakouts avoids unnecessary mean reversion trades;
  3. Take profit, stop loss and trailing stop losses effectively control risk;
  4. Optimizable parameters allow tuning for different products.

Risk Analysis

The Double Bollinger Bands Breakout strategy also has some risks:

  1. Frequent entries and stop losses may occur during ranging markets;
  2. Improper parameter settings could lead to too easy entries or difficult exits;
  3. Breakouts sometimes give false signals resulting in failed breakouts.

To address these risks, parameters could be adjusted, additional filters added, or breakouts manually monitored to reduce risk.

Optimization Directions

The Double Bollinger Bands Breakout strategy can be optimized in several ways:

  1. Optimize moving average and standard deviation parameters to fit different products;
  2. Add volume, MACD or other filters to avoid false breakouts;
  3. Use machine learning methods to dynamically optimize parameters;
  4. Copy strategy across multiple high frequency intervals to expand profit potential.

Conclusion

The Double Bollinger Bands Breakout strategy overall judges changes in price relative to Bollinger Bands to time entries in a typical trend following approach. The strategy sets profit targets using the double bands and scientific exit mechanisms to control risk. With optimized parameters and risk controls, it can achieve good results.

Parameters

NameDefaultWhat it controls
v_input_1100length
v_input_20.25pbin
v_input_31.5pbout
v_input_4falseTake Profit
v_input_5falseStop Loss
v_input_6falseTrailing Stop Loss
v_input_7falseTrailing Stop Loss Offset

Source Pine Script

/*backtest
start: 2023-12-17 00:00:00
end: 2023-12-24 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy("BB Strat",default_qty_type = strategy.percent_of_equity, default_qty_value = 100,currency="USD",initial_capital=100, overlay=true)
l=input(title="length",defval=100)
pbin=input(type=float,step=.1,defval=.25)
pbout=input(type=float,step=.1,defval=1.5)
ma=sma(close,l)
sin=stdev(ma,l)*pbin
sout=stdev(ma,l)*pbout
inu=sin+ma
inb=-sin+ma
outu=sout+ma
outb=-sout+ma
plot(inu,color=lime)
plot(inb,color=lime)
plot(outu,color=red)
plot(outb,color=yellow)

inpTakeProfit = input(defval = 0, title = "Take Profit", minval = 0)
inpStopLoss = input(defval = 0, title = "Stop Loss", minval = 0)
inpTrailStop = input(defval = 0, title = "Trailing Stop Loss", minval = 0)
inpTrailOffset = input(defval = 0, title = "Trailing Stop Loss Offset", minval = 0)
useTakeProfit = inpTakeProfit >= 1 ? inpTakeProfit : na
useStopLoss = inpStopLoss >= 1 ? inpStopLoss : na
useTrailStop = inpTrailStop >= 1 ? inpTrailStop : na
useTrailOffset = inpTrailOffset >= 1 ? inpTrailOffset : na


longCondition = close>inu and rising(outu,1) 
exitlong = (open[1]>outu and close<outu) or crossunder(close,ma)

shortCondition = close<inb and falling(outb,1)
exitshort = (open[1]<outb and close>outb) or crossover(close,ma)

strategy.entry(id = "Long", long=true, when = longCondition)
strategy.close(id = "Long", when = exitlong)
strategy.exit("Exit Long", from_entry = "Long", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset, when=exitlong)

strategy.entry(id = "Short", long=false, when = shortCondition)
strategy.close(id = "Short", when = exitshort)
strategy.exit("Exit Short", from_entry = "Short", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset, when=exitshort)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-25. 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/Double-Bollinger-Bands-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