0bps

Strategy vault / Breakout

Adaptive Bollinger Bands Dynamic Position Management Strategy

This strategy is an adaptive trading system based on Bollinger Bands, managing positions by dynamically monitoring the relationship between price and the bands. It uses a 20-day moving average as the middle band, 2…

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

IMG

Overview

This strategy is an adaptive trading system based on Bollinger Bands, managing positions by dynamically monitoring the relationship between price and the bands. It uses a 20-day moving average as the middle band, 2 standard deviations for channel width, and combines breakout confirmation with time period analysis to trigger trading signals for optimized capital allocation.

Strategy Principle

The strategy applies the statistical principles of Bollinger Bands, controlling price fluctuations within a normal distribution range. Specifically:

  1. Uses 20-day Simple Moving Average (SMA) to construct the middle band
  2. Sets upper and lower bands using 2 standard deviations to form price fluctuation range
  3. Buys 50% position when price breaks above upper band by 5% or stays above it for 1 hour
  4. Reduces position by 10% on first return to middle band, 50% when price falls below lower band by 5%
  5. Controls risk and optimizes returns through phased position building and reduction

Strategy Advantages

  1. Combines trend following and mean reversion, maintaining stability in different market environments
  2. Employs dynamic position management to avoid risks from excessive holdings
  3. Uses time confirmation to filter false breakout signals, improving trading reliability
  4. Phased position reduction strategy locks in partial profits while maintaining upside potential
  5. Strategy logic is simple and clear, easy to understand and execute

Strategy Risks

  1. May trigger frequent trading in volatile markets, increasing transaction costs
  2. Fixed Bollinger Bands parameters may not adapt to all market conditions
  3. Breakout confirmation time period settings might miss important trading opportunities
  4. Phased position reduction may exit positions too early in strong trends
  5. Aggressive capital management requires sufficient funding reserves

Strategy Optimization Directions

  1. Introduce adaptive Bollinger Bands parameters that adjust dynamically based on market volatility
  2. Add volume indicators as auxiliary confirmation for trading signals
  3. Optimize position management system by adjusting position sizes based on trend strength
  4. Incorporate stop-loss mechanisms for effective downside risk control
  5. Consider combining with other technical indicators to improve signal accuracy

Summary

The strategy establishes a complete trading system through Bollinger Bands and time period analysis, striking a balance between trend following and risk control. While there is room for optimization, the overall design philosophy aligns with core quantitative trading principles and has practical application value. Investors are advised to make appropriate adjustments based on their risk tolerance and capital size in live trading.

Source Pine Script

/*backtest
start: 2024-11-11 00:00:00
end: 2024-12-10 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Bollinger Bands Strategy", overlay=true)

// Set Bollinger Bands
length = 20
source = close
mult = 2.0
basis = ta.sma(source, length)
dev = mult * ta.stdev(source, length)
upper = basis + dev
lower = basis - dev

// Draw Bollinger Bands
plot(upper, color=color.red, linewidth=1)
plot(basis, color=color.blue, linewidth=1)
plot(lower, color=color.green, linewidth=1)

// Set buy condition: break above the Bollinger channel high5%Or continue1Hour above high
breakout_level = upper * 1.01

hour_breakout = ta.change(time("60")) == 1 and close > upper

buy_condition = (close > breakout_level or hour_breakout)
if (buy_condition)
    strategy.entry("Buy", strategy.long, qty=0.5)

// Set sell conditions: first backtest middle line, break below the low5%or rebound to the midline
sell_10_condition = ta.crossover(close, basis) and strategy.opentrades > 0
sell_50_condition = close < lower * 0.95

// Sell10%In stock
if (sell_10_condition)
    strategy.close("Buy", qty=0.1)

// Sell50%In stock
if (sell_50_condition)
    strategy.close("Buy", qty=0.5)

// Monitor buy and sell signals
plotshape(series=buy_condition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(series=sell_10_condition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell 10% Signal")
plotshape(series=sell_50_condition, location=location.abovebar, color=color.blue, style=shape.labeldown, title="Sell 50% Signal")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-12-12. 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/Adaptive-Bollinger-Bands-Dynamic-Position-Management-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