Code Library / Bollinger Bands

Pine Script Double BB

Double Bollinger Bands with 1 and 2 SD for trend zones.

Language: Pine Script · Category: Bollinger Bands · Tags: double BB, Bollinger Bands, Pine Script, trend zones, strategy

Source code

//@version=5
indicator("Double BB",overlay=true)
b=ta.sma(close,20); d=ta.stdev(close,20)
p1u=plot(b+d,"+1SD",color.blue); p1d=plot(b-d,"-1SD",color.blue)
p2u=plot(b+d*2,"+2SD",color.red); p2d=plot(b-d*2,"-2SD",color.red)
plot(b,"Basis",color.yellow,2)
fill(p1u,p2u,color.new(color.green,90)); fill(p1d,p2d,color.new(color.red,90))

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own Pine Script project, compile it, and test it on a demo account with your broker's real spreads before relying on it. You can convert it to MQL4 or MQL5 with the Pine Script converter.

Related snippets