N=40
bollUp=BollingerUp[20](close)
bollDw=BollingerDown[20](close)
Pboll = (close-bolldw)/(bollUp-bollDw )*100
Signal = 0
IF (BarIndex > 10+1+N) THEN
///divergencia bajista
IF (Pboll[1]>Pboll AND Pboll[1]>Pboll[2]) THEN
extremum2=Pboll[1]
extremum1=highest[N](Pboll)
preciomax2=close[1]
preciomax=Highest[N](close)
IF(extremum2<extremum1 AND preciomax2>preciomax[1]) THEN
for i=1 to N
if Pboll[i]=extremum1 then
signal=2
endif
next
endif
endif
///divergencia alcista
IF (Pboll[1]<Pboll AND Pboll[1]<Pboll[2]) THEN
extremum22=Pboll[1]
extremum11=lowest[N](Pboll)
preciomin2=close[1]
preciomin=lowest[N](close)
IF(extremum22>extremum11 AND preciomin2<preciomin[1]) THEN
for i2=1 to N
if Pboll[i2]=extremum11[1] then
signal=1
endif
next
ENDIF
ENDIF
endif
screener[signal](Signal AS "1=↑, 2=↓")