Strategy vault / Trend following
Bollinger Band Width Scaling Double Moving Average Trend Filter Strategy
This strategy generates trading signals based on Bollinger Bands and double moving averages, with trend filtering to target high win rate and good profit-loss ratio. 1. Use Bollinger Band upper, middle and lower…

This strategy generates trading signals based on Bollinger Bands and double moving averages, with trend filtering to target high win rate and good profit-loss ratio.
Strategy Logic
Use Bollinger Band upper, middle and lower bands for long/short signal generation. Sell when price touches upper band, buy when touches lower band.
Use 20-period medium-term and 60-period long-term moving averages to determine trend direction. Uptrend when short MA crosses above long MA, downtrend when crosses below.
Dynamically adjust stop loss position based on Bollinger Band width. When width greater than 0.5%, stop loss at lower band. When less than 0.5%, reduce stop loss to half lower band range.
Entry conditions: Breaking lower band as buy signal during uptrend. Breaking upper band as sell signal during downtrend.
Exit conditions: Take profit when touching upper band or short MA on longs. Take profit when touching lower band or short MA on shorts.
Stop loss conditions: Stop out when price breaks below lower band dynamic range on longs. Stop out when price breaks above upper band dynamic range on shorts.
Advantages
Using double MAs to determine trend helps filter noise from non-trending or range-bound markets.
BB middle band provides support/resistance, upper/lower bands serve as dynamic stop loss levels to control risk.
Adjusting stop loss range based on BB width reduces chance of being stopped out while keeping stop reasonable.
Trading in direction of trend leads to higher win rate.
Risks
Double MAs can generate false breakouts frequently, missing trend turning points. Can shorten MA periods.
BBs can get whipsawed in choppy, non-trending markets. Can reduce trade frequency.
Stop loss near support/resistance levels prone to being taken out. Can allow wider stop loss range.
Unable to capitalize on short-term pullbacks effectively. Can shorten holding period.
Enhancement Opportunities
Optimize MA periods to find best fit for market conditions.
Optimize BB multiplier parameter to balance stop loss being hit.
Add other indicators for multi-factor confirmation to improve signal quality.
Incorporate volume/momentum to confirm trend, avoid divergence.
Money management optimization e.g. fixed fractional, fixed stop loss to control single trade risk.
Price shock handling e.g. large overnight gaps.
Summary
This is an overall robust strategy using double MAs for trend direction and BBs for support/resistance and dynamic stops. Limitations exist like false trend signals and stops too close. Further optimizations can be made across MA system, stop loss strategy, money management etc. to increase robustness across various market conditions. Overall an excellent strategy for beginners with its high win rate, good risk-reward profile and simple yet effective logic.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 20 | Length |
| v_input_2 | 4 | multiplier |
| v_input_3 | 60 | Trend Time Frame |
| v_input_4 | true | Use Trend Filter |
| v_input_5_close | 0 | Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
Source Pine Script
/*backtest
start: 2022-10-18 00:00:00
end: 2023-10-24 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy(title="yuthavithi BB Scalper 2 strategy", overlay=true)
len = input(20, minval=1, title="Length")
multiplier = input(4, minval=1, title="multiplier")
trendTimeFrame = input(60, minval=1, title="Trend Time Frame")
useTrendFilter = input(true, type=bool, title = "Use Trend Filter")
src = input(close, title="Source")
out = sma(src, len)
//plot(out, title="SMA", color=blue)
stdOut = stdev(close, len)
bbUpper = out + stdOut * multiplier
bbLower = out - stdOut * multiplier
bbUpper2 = out + stdOut * (multiplier / 2)
bbLower2 = out - stdOut * (multiplier / 2)
bbUpperX2 = out + stdOut * multiplier * 2
bbLowerX2 = out - stdOut * multiplier * 2
bbWidth = (bbUpper - bbLower) / out
closeLongTerm = request.security(syminfo.tickerid, tostring(trendTimeFrame), close)
smaLongTerm = request.security(syminfo.tickerid, tostring(trendTimeFrame), sma(close,20))
//plot(smaLongTerm, color=red)
trendUp = useTrendFilter ? (closeLongTerm > smaLongTerm) : true
trendDown = useTrendFilter? (closeLongTerm < smaLongTerm) : true
bearish = ((cross(close,bbUpper2) == 1) or (cross(close,out) == 1)) and (close[1] > close) and trendDown
bullish = ((cross(close,bbLower2) == 1) or (cross(close,out) == 1)) and (close[1] < close) and trendUp
closeBuy = (high[1] > bbUpper[1]) and (close < bbUpper) and (close < open) and trendUp
closeSell = (((low[1] < bbLower[1]) and (close > bbLower)) or ((low[2] < bbLower[2]) and (close[1] > bbLower[1]))) and (close > open) and trendDown
cutLossBuy = iff(bbWidth > 0.005, (low < bbLower) and (low[1] > bbLower[1]) and trendUp, (low < bbLowerX2) and (low[1] > bbLowerX2[1]) and trendUp)
cutLossSell = iff(bbWidth > 0.005, (high > bbUpper) and (high[1] < bbUpper[1]) and trendDown, (high > bbUpperX2) and (high[1] < bbUpperX2[1]) and trendDown)
if (bullish)
strategy.entry("Buy", strategy.long, comment="Buy")
if (bearish)
strategy.entry("Sell", strategy.short, comment="Sell")
strategy.close("Buy", closeBuy or cutLossBuy)
strategy.close("Sell", closeSell or cutLossSell)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-25. 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-Band-Width-Scaling-Double-Moving-Average-Trend-Filter-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
- Bollinger Bands Precise Crossover Quantitative StrategyPine Script · Trend following · 1h
- Going with the Trend Moving Average Crossover StrategyPine Script · Trend following · 1d
- Advanced Trend Trading Strategy Based on Bollinger Bands and Candlestick PatternsPine Script · Trend following · 12h
- Bollinger Bands and Fibonacci Trading StrategyPine Script · Trend following · 45m
- Multi Band Statistical Trend Analysis StrategyPine Script · Trend following · 1h
- Bollinger Band Crossover with Slippage and Price Impact Combined StrategyPine Script · Trend following · 1d