0bps

Strategy vault / Breakout

Bollinger Bands Breakout Strategy 449497

This strategy uses Bollinger Bands as buy and sell signals. It buys when the price breaks below the lower band and sells when it breaks above the upper band. It also employs a pyramiding approach, continuing to buy…

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

IMG

Overview

This strategy uses Bollinger Bands as buy and sell signals. It buys when the price breaks below the lower band and sells when it breaks above the upper band. It also employs a pyramiding approach, continuing to buy when the number of open positions is below a set value and selling when above it. The strategy is suitable for market conditions with clear trends.

Strategy Principle

  1. Calculate the upper, middle, and lower Bollinger Bands. The middle band is the simple moving average of the closing price, while the upper and lower bands are the middle band plus or minus a multiple of the standard deviation of the closing price.
  2. When the closing price is less than or equal to the lower band, a buy signal is generated; when it is greater than or equal to the upper band, a sell signal is generated.
  3. If the current number of open positions is less than the set pyramiding number, continue buying; if greater than the set number, sell.
  4. Plot the upper, middle, and lower Bollinger Bands on the chart.

Strategy Advantages

  1. Bollinger Bands can quantify the volatility range of prices, provide clear buy and sell signals, and are easy to operate.
  2. The pyramiding approach can amplify the profitability of trend moves.
  3. Bollinger Bands have a certain ability to identify trends and control risk, making them suitable for trend traders.

Strategy Risks

  1. When the market is in a choppy condition, frequent buy and sell signals may lead to losses.
  2. If a trend reversal occurs, the pyramiding approach amplifies the downside risk.
  3. The selection of Bollinger Band parameters needs to be optimized for different markets and timeframes; inappropriate parameters may cause the strategy to fail.

Strategy Optimization Directions

  1. It can be combined with other indicators such as RSI, MACD, etc., to secondarily confirm Bollinger Band signals and improve signal accuracy.
  2. Control the quantity and proportion of pyramiding, set stop-loss positions, and reduce downside risk.
  3. Optimize and test Bollinger Band parameters such as period and multiple to select the best parameter combination.
  4. In choppy markets, consider using a Bollinger Band channel strategy to buy low and sell high between the upper and lower bands.

Summary

The Bollinger Bands Breakout strategy uses the position of the price relative to the Bollinger Bands to generate trend-following signals, while amplifying trend profits through pyramiding. However, it performs poorly in rangebound markets, and pyramiding may amplify losses. Therefore, in actual use, it needs to be combined with other indicators to verify signals, control pyramiding risks, and optimize parameters. At the same time, the strategy should be flexibly adjusted according to market characteristics.

Parameters

NameDefaultWhat it controls
v_input_120Bollinger Bands Length
v_input_22Multiplier
v_input_310Pyramiding

Source Pine Script

/*backtest
start: 2023-04-19 00:00:00
end: 2024-04-24 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Bollinger Bands Breakout Strategy", overlay=true, initial_capital=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// Définition des paramètres
length = input(20, title="Bollinger Bands Length")
multiplier = input(2.0, title="Multiplier")
pyramiding = input(10, title="Pyramiding")

// Calcul des bandes de Bollinger
basis = ta.sma(close, length)
dev = multiplier * ta.stdev(close, length)
upper_band = basis + dev
lower_band = basis - dev

// Règles d'entrée
buy_signal = close <= lower_band
sell_signal = close >= upper_band
// Gestion des positions
if (buy_signal)
    strategy.entry("Buy", strategy.long)
if (sell_signal)
    strategy.entry("Sell", strategy.short)

// Pyramiding
if (strategy.opentrades < pyramiding)
    strategy.entry("Buy", strategy.long)
else if (strategy.opentrades > pyramiding)
    strategy.entry("Sell", strategy.short)

// Tracé des bandes de Bollinger
plot(basis, color=color.blue)
plot(upper_band, color=color.red)
plot(lower_band, color=color.green)


Published by ChaoZhang on the FMZ strategy square · last modified 2024-04-26. 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-Strategy-449497.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