0bps

Strategy vault / Mean reversion

Bollinger Bands Reversal Trend Strategy

This strategy uses the relationship between the upper band, middle band, lower band of Bollinger Bands and 200-day moving average to determine the trend direction. It goes long when price touches the lower band…

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

IMG

Overview

This strategy uses the relationship between the upper band, middle band, lower band of Bollinger Bands and 200-day moving average to determine the trend direction. It goes long when price touches the lower band during an uptrend and goes short when price touches the upper band during a downtrend.

Principles

  1. Determine trend: When both upper and lower bands of Bollinger Bands are above 200-day moving average, it is an uptrend. When both are below, it is a downtrend.
  2. Entry: Go long when price touches lower band in an uptrend. Go short when price touches upper band in a downtrend.
  3. Exit: When long, close position when price touches upper band or breaks below 250-day simple moving average. When short, close position when price touches lower band or breaks above 300-day simple moving average.

Advantages

  1. Use Bollinger Bands to determine trend direction, avoiding repetitive trading without a clear direction.
  2. Take proper entries and exits based on the volatility range of Bollinger Bands when trend direction is clear.
  3. Added filtering with moving averages, avoiding unexpected losses.

Risks and Solutions

  1. Improper Bollinger Bands parameter setting leads to misjudgment: Adjust parameters to find the optimal period length.
  2. Improper moving average parameter leading to over trading or unwanted losses: Test different parameters to find the most stable ones.
  3. Sudden market change due to major news events causes anomalies: Set stop loss to limit per trade loss.

Optimization Directions

  1. Test strategy performance across different parameter periods to find the optimal parameters.
  2. Add stop loss mechanism to avoid huge losses in anomalous market conditions.
  3. Incorporate other indicators to confirm entry signals to improve win rate.

Conclusion

This strategy determines trend direction with Bollinger Bands first. It then utilizes the volatility range of Bollinger Bands together with moving averages to form a trading system that ensures directional correctness and locks in decent profits. There are still some issues with parameter selection and stop loss that can be further improved via optimization and mechanism additions to achieve better performance.

Parameters

NameDefaultWhat it controls
v_input_int_120length
v_input_float_12.3mult
v_input_int_2200trend

Source Pine Script

/*backtest
start: 2023-11-29 00:00:00
end: 2023-12-06 00:00:00
period: 1m
basePeriod: 1m
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("boll trend", overlay=true,initial_capital=1000,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 = "mult")
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")
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) or ta.crossunder(close,ta.sma(close,300))
shortEXIT=ta.crossunder(low,lower) or ta.crossover(close,ta.sma(close,250)) 

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

if longEXIT
    strategy.close("Manylong",comment = "close long")

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

if shortEXIT
    strategy.close("Emptyshort",comment = "close short")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-07. 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-Reversal-Trend-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