0bps

Strategy vault / Trend following

Bollinger Trend Shock Trading Strategy

This strategy uses the Bollinger Bands indicator to determine market trend direction, and takes counter-trend trades when trend reversal occurs. It goes long when price breaks below the lower band in an uptrend; and…

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

IMG

Overview

This strategy uses the Bollinger Bands indicator to determine market trend direction, and takes counter-trend trades when trend reversal occurs. It goes long when price breaks below the lower band in an uptrend; and goes short when price breaks above the upper band in a downtrend. Also, a moving average is used as the benchmark for long-term trend to make the strategy more stable.

Strategy Principle

This strategy utilizes the middle band, upper band and lower band of Bollinger Bands to determine market trend direction. The middle band is the n-period exponential moving average, while the upper band and lower band are middle band +2.3 standard deviation and middle band -2.3 standard deviation respectively. When price breaks below the lower band, it indicates a current uptrend. When price breaks above the upper band, it indicates a current downtrend.

In addition, the strategy sets a 200-period simple moving average (sma) as the benchmark for long-term trend judgement. Trading signals are only triggered when BB and sma indicators agree on the same direction. This can effectively filter out some false breakouts.

The specific trading logic is as follows:

  1. Determine uptrend: BB upper band > sma, middle band > sma, lower band >= sma
  2. Determine downtrend: BB upper band < sma, middle band < sma, lower band <= sma
  3. Long condition: Uptrend + Price breaks BB lower band
  4. Exit condition: Price breaks BB upper band
  5. Short condition: Downtrend + Price breaks BB upper band
  6. Exit condition: Price breaks below BB middle band or rebounds back above the 230-period MA

Advantage Analysis

  1. BB judges trend direction effectively and captures breakout trading opportunities
  2. Adding long-term MA filter reduces risks associated with false breakouts
  3. Clear long and short logic, easy to understand and follow
  4. Strict criteria for short exit helps limit losses

Risk Analysis

  1. Potential large slippage when BB and MA issue trading signals
  2. Overly strict short conditions lead to limited short side profit
  3. Improper parameter tuning can result in too high/low trading frequency
  4. Breakout strategies prone to huge losses

Improvements:

  1. Optimize BB parameters to reduce trading frequency
  2. Set stop loss to avoid huge losses per trade
  3. Add volume filter to ensure breakout validity

Summary

Overall this is a simple and easy to understand strategy, using BB to determine trends and taking counter-trend trades at turning points. Adding short-term and benchmark indicators also helps filter signals. Still large room for optimizations, like parameter tuning, volume indicators etc. can further improve it.

Parameters

NameDefaultWhat it controls
v_input_int_120Length
v_input_float_12.3Standard deviation
v_input_int_2200Trend Boundary Line

Source Pine Script

/*backtest
start: 2023-10-23 00:00:00
end: 2023-11-22 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Aayonga

//@version=5
strategy("Bollinger trend oscillation order", overlay=true,initial_capital=10000,default_qty_type=strategy.fixed, default_qty_value=1 )
bollL=input.int(20,minval=1,title = "Length")
bollmult=input.float(2.3,minval=0,step=0.1,title = "Standard deviation")
basis=ta.ema(close,bollL)
dev=bollmult*ta.stdev(close,bollL)
upper=basis+dev
lower=basis-dev
smaL=input.int(200,minval=1,step=1,title = "Trend Boundary Line")
sma=ta.sma(close,smaL)
//Bullish trend
longT=upper>sma and basis>sma and lower>=sma
//Bearish trend
shortT=upper<sma and basis<sma and lower<=sma

//Admission
longE=ta.crossover(close,lower)
shortE=ta.crossover(close,upper)
//Appearance position

longEXIT=ta.crossover(high,upper) 
shortEXIT=ta.crossunder(close,basis) or ta.crossover(close,ta.sma(close,230)) 

if longT and longE
    strategy.entry("Many",strategy.long)

if longEXIT
    strategy.close("Many",comment = "Multiple appearances")

if shortE and shortT
    strategy.entry("Empty",strategy.short)

if shortEXIT
    strategy.close("Empty",comment = "Empty appearance")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-23. 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-Trend-Shock-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