A volatility-based strategy that uses a moving average with upper and lower bands to identify potential reversals at support and resistance levels.
When price touches or breaks below the lower Bollinger Band, it may be oversold. Enter a long position when price bounces back above the lower band.
When price touches or breaks above the upper Bollinger Band, it may be overbought. Enter a short position when price drops back below the upper band.
| Parameter | Default | Description |
|---|---|---|
| BB Length | 20 | Period for middle band (SMA) |
| StdDev Multiplier | 2.0 | Standard deviation multiplier for band width |
| Source | close | Price source for calculations |
//@version=5
strategy("Bollinger Bands Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Input parameters
length = input.int(20, title="BB Length", minval=1)
mult = input.float(2.0, title="BB StdDev Multiplier", minval=0.1, step=0.1)
src = input.source(close, title="Source")
// Calculate Bollinger Bands
[basis, upper, lower] = ta.bb(src, length, mult)
// Plot Bollinger Bands
plot(basis, color=color.blue, title="BB Middle")
plot(upper, color=color.red, title="BB Upper")
plot(lower, color=color.green, title="BB Lower")
fill(plot1=upper, plot2=lower, color=color.new(color.gray, 90))
// Generate signals
longCondition = ta.crossover(src, lower) // Price crosses above lower band
shortCondition = ta.crossunder(src, upper) // Price crosses below upper band
// Middle band exit
longExit = ta.crossover(src, basis) // Price crosses above middle
shortExit = ta.crossunder(src, basis) // Price crosses below middle
// Entry conditions
if (longCondition)
strategy.entry(id="Long", direction=strategy.long)
if (shortCondition)
strategy.entry(id="Short", direction=strategy.short)
// Exit conditions
if (longExit)
strategy.close(id="Long")
if (shortExit)
strategy.close(id="Short")
// Plot signals
plotshape(longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.tiny, text="BB BUY")
plotshape(shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.tiny, text="BB SELL")
// Alert conditions
alertcondition(longCondition, title="Buy Alert", message="Price touched lower Bollinger Band - Enter Long")
alertcondition(shortCondition, title="Sell Alert", message="Price touched upper Bollinger Band - Enter Short")