This strategy is a trend following system that combines Bollinger Bands, volatility metrics, and risk management. It captures trending opportunities by monitoring price breakouts beyond Bollinger Bands while dynamically adjusting position sizes using ATR for precise risk control. The strategy also incorporates a consolidation period detection mechanism to effectively filter false signals in ranging markets.
The strategy operates based on the following core logic: 1. Uses a 20-period moving average as the middle band of Bollinger Bands, with upper and lower bands at 2 standard deviations. 2. Identifies market consolidation periods by comparing current Bollinger Band width to its moving average. 3. During non-consolidation periods, enters long positions on upper band breakouts and short positions on lower band breakouts. 4. Utilizes 14-period ATR to dynamically calculate stop-loss levels and sets take-profit levels based on a 2:1 risk-reward ratio. 5. Automatically calculates position sizes for each trade based on 1% account risk limit and ATR value.
This strategy captures trends through Bollinger Bands breakouts while incorporating a comprehensive risk control system. Its strengths lie in high adaptability and controlled risk, though attention must be paid to false breakouts and trend reversal risks. The strategy has room for further improvement through adding trend confirmation indicators and optimizing parameter adjustment mechanisms. Overall, it represents a logically sound and practical trend following strategy.
/*backtest start: 2019-12-23 08:00:00 end: 2025-01-08 08:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Bollinger Bands Breakout Strategy", overlay=true) // Input parameters length = input(20, title="Bollinger Bands Length") stdDev = input(2.0, title="Standard Deviation") riskRewardRatio = input(2.0, title="Risk/Reward Ratio") atrLength = input(14, title="ATR Length") riskPercentage = input(1.0, title="Risk Percentage per Trade") // Calculate Bollinger Bands basis = ta.sma(close, length) dev = stdDev * ta.stdev(close, length) upperBand = basis + dev lowerBand = basis - dev // Calculate ATR for position sizing atr = ta.atr(atrLength) // Plot Bollinger Bands plot(basis, color=color.blue, title="Basis") plot(upperBand, color=color.red, title="Upper Band") plot(lowerBand, color=color.green, title="Lower Band") // Market Consolidation Detection isConsolidating = (upperBand - lowerBand) < ta.sma(upperBand - lowerBand, length) * 0.5 // Breakout Conditions longCondition = ta.crossover(close, upperBand) and not isConsolidating shortCondition = ta.crossunder(close, lowerBand) and not isConsolidating // Risk Management: Calculate position size equity = strategy.equity riskAmount = equity * (riskPercentage / 100) positionSize = riskAmount / (atr * riskRewardRatio) // Execute trades with risk management if (longCondition) strategy.entry("Long", strategy.long, qty=positionSize) strategy.exit("Take Profit", from_entry="Long", limit=close + atr * riskRewardRatio, stop=close - atr) if (shortCondition) strategy.entry("Short", strategy.short, qty=positionSize) strategy.exit("Take Profit", from_entry="Short", limit=close - atr * riskRewardRatio, stop=close + atr) // Alert conditions for breakouts alertcondition(longCondition, title="Long Breakout", message="Long breakout detected!") alertcondition(shortCondition, title="Short Breakout", message="Short breakout detected!")