0bps

Strategy vault / Breakout

Breakout Bollinger Bands Oscillation Trading Strategy

The Breakout Bollinger Bands Oscillation Trading Strategy is a trading strategy for when the market is in an oscillating state. This strategy uses the Bollinger Bands indicator to judge the oscillating condition of…

Author
ChaoZhang
Complexity
Intermediate · 59 lines
Parameters
11
Backtest bar
4h · intraday
Tested on
BTC/USDT · futures

IMG

Overview

The Breakout Bollinger Bands Oscillation Trading Strategy is a trading strategy for when the market is in an oscillating state. This strategy uses the Bollinger Bands indicator to judge the oscillating condition of the market and sends out trading signals when the price touches the upper or lower rails of the Bollinger Bands. Unlike traditional trend following strategies, this strategy is more suitable for range-bound sideways markets.

Strategy Logic

This strategy is mainly implemented based on the Bollinger Bands indicator. Bollinger Bands consist of a middle rail, upper rail and lower rail. When the price approaches the upper or lower rail, it represents over-optimism or over-pessimism in the market, which means a relatively high probability of reversal.

Specifically, this strategy first uses the DMI indicator to determine if the market is in an oscillating state. When the difference between +DMI and -DMI is less than 20, the market is considered to be ranging sideways. Under this condition, go long when the price breaks above the lower rail, and go short when the price breaks below the upper rail. The stop loss point is set near the opposite rail.

Advantages

Compared with trend following strategies, this strategy is more suitable for range-bound market environments and will not lose money chasing trends. Compared with traditional oscillation trading strategies, this strategy can more accurately judge the overbought and oversold situations in the market by using the Bollinger Bands indicator, thus improving the probability of entering the market.

Risks

This strategy mainly relies on Bollinger Bands to determine market oscillation and overbought/oversold conditions. When Bollinger Bands diverge or contract abnormally, it may lead to wrong signals. In addition, the stop loss point is close, so a single stop loss could be relatively large. It is recommended to optimize the stop loss strategy with money management.

Optimization

We can consider combining other indicators to filter entry signals, such as RSI and other oscillators, to improve entry accuracy. In addition, optimizing the stop loss strategy is also very important to avoid a single large stop loss. We can also choose trading varieties that are more suitable for this strategy, such as low market cap coins.

Conclusion

In general, this strategy is suitable for oscillating markets and can be used when trend strategies fail. But there is still room for improving its effectiveness by judging market states with indicators. We can further improve this strategy by methods like multi-indicator combos, money management, etc. to make it more stable and profitable.

Parameters

NameDefaultWhat it controls
v_input_1trueFrom Month
v_input_2trueFrom Day
v_input_32021From Year
v_input_412Thru Month
v_input_531Thru Day
v_input_62022Thru Year
v_input_7trueShow Date Range
v_input_820lengthBB
v_input_9_close0Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_102StdDev
v_input_11falseOffset

Source Pine Script

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

//@version=4
strategy(shorttitle='Sideways Strategy DMI + Bollinger Bands',title='Sideways Strategy DMI + Bollinger Bands (by Coinrule)', overlay=true, initial_capital = 100, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent, commission_value=0.1)

// Works on ETHUSD 3h, 1h, 2h, 4h

//Backtest dates
fromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)
fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)
fromYear  = input(defval = 2021, title = "From Year",       type = input.integer, minval = 1970)
thruMonth = input(defval = 12,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)
thruDay   = input(defval = 31,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)
thruYear  = input(defval = 2022, title = "Thru Year",       type = input.integer, minval = 1970)

showDate  = input(defval = true, title = "Show Date Range", type = input.bool)

start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish window
window()  => true

[pos_dm, neg_dm, adx] = dmi(14, 14)


lengthBB = input(20, minval=1)
src = input(close, title="Source")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src, lengthBB)
dev = mult * stdev(src, lengthBB)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)

sideways = (abs(pos_dm - neg_dm) < 20)



//Stop_loss= ((input (3))/100)
//Take_profit= ((input (2))/100)

//longStopPrice  = strategy.position_avg_price * (1 - Stop_loss)
//longTakeProfit = strategy.position_avg_price * (1 + Take_profit)

//closeLong = close < longStopPrice or close > longTakeProfit or StopRSI


//Entry 
strategy.entry(id="long", long = true, when = sideways and (crossover(close, lower)) and window())


//Exit
strategy.close("long", when = (crossunder(close, upper)))

Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-21. 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/Breakout-Bollinger-Bands-Oscillation-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