Strategy vault / Trend following
Dual Bandpass Filter Strategy
The Dual Bandpass Filter strategy is adapted from the strategy published by Broder in Stocks & Commodities magazine in 2010. It generates trading signals by calculating the value of Broder's bandpass filter to…

Overview
The Dual Bandpass Filter strategy is adapted from the strategy published by Broder in Stocks & Commodities magazine in 2010. It generates trading signals by calculating the value of Broder's bandpass filter to identify price fluctuations in stocks. It goes short when the bandpass filter value is higher than the threshold, and goes long when it is lower, to follow the trend.
Strategy Logic
The key steps of this strategy are:
Initialize parameters including bandpass length
Length, fluctuation coefficientDelta, short zone thresholdSellZone, and long zone thresholdBuyZone.Calculate the Broder bandpass filter
BPusing a series of trigonometric functions.Determine position direction: go short if
BPis aboveSellZone; go long if belowBuyZone; otherwise, maintain current position.Output signals: generate long/short signals based on position direction.
Set bar colors based on signal results.
Plot the bandpass filter curve.
This strategy captures short-term fluctuations using the Broder bandpass filter, and generates trading signals when the fluctuations reach certain magnitude to follow the trend.
Advantage Analysis
More sensitive to market fluctuations based on the Broder bandpass filter, which can catch short-term trends.
The sensitivity can be adjusted through parameter tuning to adapt to different market environments.
Simple and clear strategy logic, easy to understand and implement.
Parameters can be easily optimized to find the best combination.
Visual bandpass filter curve intuitively shows market fluctuations.
Risk Analysis
Overly optimized bandpass filter may become too sensitive and generate false signals.
Unable to determine fluctuation end points, may lead to expanding losses.
High trading frequency may increase costs and slippage risks.
Vulnerable to black swan events that trigger false signals.
Parameters need adjusting for different products and markets.
Consider setting stop loss to control loss per trade.
Extend exit time or add filters to reduce false signals.
Optimization Directions
Optimize parameters to find the best combination, evaluating win rate, profit ratio, Sharpe ratio etc.
Add filters like moving average cross, price patterns to avoid trading in non-trending areas.
Consider combining parameters across multiple instruments for basket trading to diversify risks.
Add stop loss logic to control loss per trade, like dynamic stops or trailing stops.
Add profit taking like moving profit stops to lock in gains. Different levels can be set for different trend stages.
Optimize entry signals to avoid false signals in ranging markets. Consider longer holding periods or breakout signals.
Expand to a cross-asset arbitrage system utilizing price differentials for hedging.
Backtest optimization for best asset selection and rebalancing strategies.
Summary
The Dual Bandpass Filter strategy judges price fluctuations using Broder's bandpass filter and generates signals when the fluctuations reach thresholds, with the advantage of high sensitivity to short-term trends and easy implementation. However, it is sensitive to parameters and trading frequency, requiring optimization to reduce false signals and manage risks. Overall, it provides an option for catching short-term trends, but overfitting should be avoided, and other technical tools can be combined for trading.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 20 | Length |
| v_input_2 | 0.5 | Delta |
| v_input_3 | 5 | SellZone |
| v_input_4 | -5 | BuyZone |
| v_input_5 | false | Trade reverse |
Source Pine Script
/*backtest
start: 2022-10-17 00:00:00
end: 2023-10-23 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 18/09/2018
// The related article is copyrighted material from
// Stocks & Commodities Mar 2010
// You can use in the xPrice any series: Open, High, Low, Close, HL2, HLC3, OHLC4 and ect...
//
// You can change long to short in the Input Settings
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title="Bandpass Filter Strategy ver 2.0")
Length = input(20, minval=1)
Delta = input(0.5)
SellZone = input(5, step = 0.01)
BuyZone = input(-5, step = 0.01)
reverse = input(false, title="Trade reverse")
hline(BuyZone, color=green, linestyle=line)
hline(SellZone, color=red, linestyle=line)
xPrice = hl2
hline(0, color=blue, linestyle=line)
beta = cos(3.14 * (360 / Length) / 180)
gamma = 1 / cos(3.14 * (720 * Delta / Length) / 180)
alpha = gamma - sqrt(gamma * gamma - 1)
BP = 0.5 * (1 - alpha) * (xPrice - xPrice[2]) + beta * (1 + alpha) * nz(BP[1]) - alpha * nz(BP[2])
pos = iff(BP > SellZone, 1,
iff(BP <= BuyZone, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(BP, color=red, title="Bandpass Filter Strategy")Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-24. 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/Dual-Bandpass-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
- 200 EMA VWAP MFI Trend Following StrategyPine Script · Trend following · 1d
- 4 EMA Trend StrategyPine Script · Trend following · 1d
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR Dynamic Profit Target and Stop Loss StrategyPine Script · Trend following · 1d
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h