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…

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
- 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.
- Entry: Go long when price touches lower band in an uptrend. Go short when price touches upper band in a downtrend.
- 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
- Use Bollinger Bands to determine trend direction, avoiding repetitive trading without a clear direction.
- Take proper entries and exits based on the volatility range of Bollinger Bands when trend direction is clear.
- Added filtering with moving averages, avoiding unexpected losses.
Risks and Solutions
- Improper Bollinger Bands parameter setting leads to misjudgment: Adjust parameters to find the optimal period length.
- Improper moving average parameter leading to over trading or unwanted losses: Test different parameters to find the most stable ones.
- Sudden market change due to major news events causes anomalies: Set stop loss to limit per trade loss.
Optimization Directions
- Test strategy performance across different parameter periods to find the optimal parameters.
- Add stop loss mechanism to avoid huge losses in anomalous market conditions.
- 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
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 20 | length |
| v_input_float_1 | 2.3 | mult |
| v_input_int_2 | 200 | trend |
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.
/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- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- Advanced Quantitative Trading Strategy Combining RSI Divergence and Moving AveragesPine Script · Mean reversion · 1h
- Enhanced Bollinger Mean Reversion Quantitative StrategyPine Script · Mean reversion · 1d
- Reversal Trading Strategy with Bollinger Bands RSI ADX and ATRPine Script · Mean reversion · 1h
- The Smooth Moving Average Ribbon StrategyPine Script · Mean reversion · 1h
- Bollinger Band Mean Reversion Strategy with Intraday Intensity IndexPine Script · Mean reversion · 2h