
This strategy is a momentum tracking trading system based on Bollinger Bands indicator. It identifies potential breakout opportunities by monitoring the relationship between price and the upper Bollinger Band, and closes positions when price breaks below the lower band. Bollinger Bands consist of three lines: the middle band (moving average), upper and lower bands (calculated using standard deviation). The strategy supports multiple types of moving averages and allows parameter adjustment based on trader preferences.
The core logic of the strategy is based on the following points: 1. Entry Signal: When the closing price breaks above the upper Bollinger Band, indicating a potential strong uptrend, a long position is opened. 2. Exit Signal: When the closing price falls below the lower Bollinger Band, suggesting momentum exhaustion, the position is closed. 3. Bollinger Bands Calculation: The middle band uses selectable moving average types (SMA, EMA, SMMA, WMA, VWMA), and band width is determined by standard deviation multiplier. 4. Trade Management: The strategy executes trades within a specified time window, uses 100% capital per trade, and considers commission and slippage factors.
This is a trend-following strategy based on Bollinger Bands, capturing market trends by observing the relationship between price and the bands. The strategy is well-designed with good adaptability and risk management mechanisms. Through the suggested optimization directions, the strategy’s stability and profitability can be further enhanced. It is particularly suitable for volatile markets, but traders need to adjust parameters and risk control measures according to actual conditions.
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title="Demo GPT - Bollinger Bands Strategy", overlay=true, initial_capital=100000, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3)
// Inputs
length = input.int(20, minval=1, title="Length")
maType = input.string("SMA", "Basis MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval=-500, maxval=500)
startDate = input(timestamp('01 Jan 2018 00:00 +0000'), title="Start Date")
endDate = input(timestamp('31 Dec 2069 23:59 +0000'), title="End Date")
// Moving Average Function
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// Calculations
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
// Plotting
plot(basis, "Basis", color=#2962FF, offset=offset)
p1 = plot(upper, "Upper", color=#F23645, offset=offset)
p2 = plot(lower, "Lower", color=#089981, offset=offset)
fill(p1, p2, title="Background", color=color.rgb(33, 150, 243, 95))
// Strategy Logic
inTradeWindow = true
longCondition = close > upper and inTradeWindow
exitCondition = close < lower and inTradeWindow
if (longCondition)
strategy.entry("Long", strategy.long, qty=1)
if (exitCondition)
strategy.close("Long")