// Calculate the Bollinger Bands with exponential moving average
Period = 20 //20 periods
Deviation = 2 //2x standard deviation
MiddleBand = Average[Period,1](Close)
BollUp = MiddleBand + Deviation * Std[Period](Close)
BollDown = MiddleBand - Deviation * Std[Period](Close)
// Check for conditions where candle starts or ends outside the bands
CandleAboveBB = (Open > BollUp and Close > BollUp)
CandleBelowBB = (Open < BollDown and Close < BollDown)
// Draw signals on the chart
IF CandleAboveBB THEN
DrawArrowUp(BarIndex,High)Coloured("Green")
EndIf
If CandleBelowBB THEN
DrawArrowDown(BarIndex,Low)Coloured("Red")
EndIf
RETURN MiddleBand,BollUp coloured("Green"),BollDown coloured("Red")