Strategy vault / Trend following
Trend Following Strategy Based on Bollinger Band Oscillator
The core idea of this strategy is to identify trends using the Bollinger Band Oscillator and enter positions when trends change. It goes long when price breaks above the upper band and goes short when price breaks…
Overview
The core idea of this strategy is to identify trends using the Bollinger Band Oscillator and enter positions when trends change. It goes long when price breaks above the upper band and goes short when price breaks below the lower band, with a trend following approach to profit.
Strategy Logic
The strategy mainly uses the Bollinger Band Oscillator to determine trend direction. The formula for BBO is:
BBO = (Close - N-day Moving Average) / (2 * N-day Standard Deviation) * 100
Where Close is the closing price, N-day Moving Average is the N-day simple moving average of close, and N-day Standard Deviation is the N-day standard deviation of close.
The strategy first calculates the 65-day BBO, then the 30-day moving average of BBO. When BBO crosses above its MA, it signals an uptrend, go long. When BBO crosses below its MA, it signals a downtrend, go short.
After entering positions, the strategy uses moving stop loss, fixed take profit and trailing stop loss to control risks and lock in profits. The parameters can be optimized based on backtest results.
Advantages
BBO is sensitive to trend changes.
Moving stop loss controls individual loss when trend reverses.
Fixed take profit locks in profits when trend is correct.
Trailing stop loss maximizes profit for a single trade.
The strategy is simple and intuitive.
Risks
BBO can give false signals.
Improper stop loss/take profit may exit too early.
Fixed take profit may exit too early, missing further profits.
Parameters need optimization to avoid overfitting.
Potentially large drawdown, sufficient capital required.
Optimization
Optimize BBO and MA parameters.
Test different stop loss methods like ATR, percentage.
Optimize fixed take profit and trailing stop loss.
Add filters to avoid false signals.
Optimize position sizing for different markets.
Test strategy effectiveness across instruments and timeframes.
Conclusion
The strategy identifies trend changes using BBO and enters positions accordingly. It controls risks and locks in profits with various types of exits. The strategy is simple and intuitive but requires parameter optimization. It can perform well in trending markets if optimized properly, but false signals and improper exits need to be watched out for.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 65 | length |
| v_input_2 | 30 | lengthMA |
| v_input_3 | false | TP |
| v_input_4 | false | SL |
| v_input_5 | true | TS |
| v_input_6 | 10 | TO |
Source Pine Script
/*backtest
start: 2022-10-03 00:00:00
end: 2023-10-09 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy(title="Strategy CCT Bollinger Band Oscillator", shorttitle="Hornkild", calc_on_order_fills=true, default_qty_type=strategy.percent_of_equity, default_qty_value=50, overlay=false)
length=input(65)
lengthMA=input(30)
src=close
cctbbo=100 * ( src + 2*stdev( src, length) - sma( src, length ) ) / ( 4 * stdev( src, length ) )
//ul=hline(100, color=gray, editable=true)
//ll=hline(0, color=gray)
//hline(50, color=gray)
//fill(ul,ll, color=blue)
//plot(cctbbo, color=blue, linewidth=2)
//plot(ema(cctbbo, lengthMA), color=red)
TP = input(0) * 10
SL = input(0) * 10
TS = input(1) * 10
TO = input(10) * 10
CQ = 100
TPP = (TP > 0) ? TP : na
SLP = (SL > 0) ? SL : na
TSP = (TS > 0) ? TS : na
TOP = (TO > 0) ? TO : na
longCondition = crossover(cctbbo, ema(cctbbo, lengthMA))
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = crossunder(cctbbo, ema(cctbbo, lengthMA))
if (shortCondition)
strategy.entry("Short", strategy.short)
strategy.exit("Close Short", "Short", qty_percent=CQ, profit=TPP, loss=SLP, trail_points=TSP, trail_offset=TOP)
strategy.exit("Close Long", "Long", qty_percent=CQ, profit=TPP, loss=SLP, trail_points=TSP, trail_offset=TOP)Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-10. 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/Trend-Following-Strategy-Based-on-Bollinger-Band-Oscillator.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
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual Moving Average Crossover Dynamic Position Optimization Strategy with EMA Cross Signal SystemPine Script · Trend following · 1h
- EMA Cross Trend Following Strategy with SMA Stop Loss and Re Entry MechanismPine Script · Trend following · 1h
- EMA and RSI Trend Trading StrategyPine Script · Trend following · 1d
- Adaptive Trend Following StrategyPine Script · Trend following · 4h