
Chiến lược này là một hệ thống theo xu hướng kết hợp dải Bollinger, tính biến động và quản lý rủi ro. Công cụ này chủ yếu nắm bắt các cơ hội xu hướng bằng cách theo dõi cách giá vượt qua đường trên và đường dưới của Dải Bollinger, đồng thời điều chỉnh động quy mô vị thế kết hợp với ATR để kiểm soát rủi ro chính xác. Chiến lược này cũng kết hợp một cơ chế xác định thời kỳ củng cố thị trường để lọc hiệu quả các tín hiệu sai trong thị trường biến động.
Chiến lược này hoạt động dựa trên logic cốt lõi sau:
Chiến lược này nắm bắt xu hướng thông qua sự đột phá của dải Bollinger và kết hợp với hệ thống kiểm soát rủi ro hợp lý. Ưu điểm của nó là khả năng thích ứng mạnh mẽ và rủi ro có thể kiểm soát được, nhưng chúng ta vẫn cần lưu ý đến rủi ro đột phá giả và đảo ngược xu hướng. Vẫn còn chỗ để cải thiện chiến lược hơn nữa bằng cách thêm các chỉ báo xác nhận xu hướng, tối ưu hóa cơ chế điều chỉnh tham số, v.v. Nhìn chung, đây là một chiến lược đi theo xu hướng với logic rõ ràng và tính thực tiễn cao.
/*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!")