This strategy is a quantitative trading system that combines Bollinger Bands breakout with moving average trends. The system automatically captures market opportunities by monitoring price relationships with Bollinger Bands while using a 100-day moving average for trend confirmation. It implements dynamic position sizing based on account equity for automatic risk management.
The core logic is based on the following key elements:
This strategy builds a complete quantitative trading system by combining Bollinger Bands and moving averages. While maintaining simple logic, it implements core functionalities including signal generation, position management, and risk control. Though there are areas for optimization, the overall design is sound and has practical application value. It’s recommended to thoroughly optimize parameters and validate through backtesting before live implementation, with adjustments made according to specific market characteristics.
/*backtest start: 2024-10-01 00:00:00 end: 2024-10-31 23:59:59 period: 1h basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("BB Breakout with MA 100 Strategy", overlay=true) // Parameter Bollinger Bands length = input(20, title="BB Length") stdDev = input(2.0, title="BB Standard Deviation") // Hitung Bollinger Bands basis = ta.sma(close, length) dev = stdDev * ta.stdev(close, length) upperBB = basis + dev lowerBB = basis - dev // Hitung Moving Average 100 ma100 = ta.sma(close, 100) // Logika untuk sinyal beli dan jual longCondition = close > upperBB and close[1] <= upperBB[1] shortCondition = close < lowerBB and close[1] >= lowerBB[1] // Menentukan ukuran posisi (jumlah lot) size = strategy.equity / close // Menentukan ukuran posisi berdasarkan ekuitas saat ini // Eksekusi order if (longCondition) strategy.entry("Long", strategy.long, qty=size) if (shortCondition) strategy.entry("Short", strategy.short, qty=size) // Menutup posisi ketika kondisi terbalik if (longCondition and strategy.position_size < 0) strategy.close("Short") if (shortCondition and strategy.position_size > 0) strategy.close("Long") // Plotting plot(upperBB, color=color.red, title="Upper BB") plot(lowerBB, color=color.green, title="Lower BB") plot(basis, color=color.blue, title="Basis BB") plot(ma100, color=color.orange, title="MA 100") // Menambahkan informasi ke grafik bgcolor(longCondition ? color.new(color.green, 90) : na, title="Buy Signal Background") bgcolor(shortCondition ? color.new(color.red, 90) : na, title="Sell Signal Background")