/////////////////////////////////////////////
// Momentum Divergences (based on MACD divergences on MACD by Jose Callao
N=50 //N is the number of bars to look back for a divergence.
P=12
MyMOM = Momentum[P](close)
Signal = 0
IF (BarIndex > P+N) THEN
///divergencia bajista
IF (MyMOM[1]>MyMOM AND MyMOM[1]>MyMOM[2]) THEN
extremum2=MyMOM[1]
extremum1=highest[N](MyMOM)
preciomax2=close[1]
preciomax=Highest[N](close)
IF(extremum2<extremum1 AND preciomax2>preciomax[1]) THEN
for i=1 to N
if MyMOM[i]=extremum1 then
//zz=i
Signal = 2
//drawsegment (barindex[1], MyMOM[1], barindex[zz], MyMOM[zz]) coloured(200,0,0)
endif
next
endif
endif
///divergencia alcista
IF (MyMOM[1]<MyMOM AND MyMOM[1]<MyMOM[2]) THEN
extremum22=MyMOM[1]
extremum11=lowest[N](MyMOM)
preciomin2=close[1]
preciomin=lowest[N](close)
IF(extremum22>extremum11 AND preciomin2<preciomin[1]) THEN
for i2=1 to N
if MyMOM[i2]=extremum11[1] then
//zz2=i2
Signal = 1
//drawsegment(barindex[1], MyMOM[1], barindex[zz2], MyMOM[zz2]) coloured(0,200,0)
endif
next
ENDIF
ENDIF
endif
Screener[Signal](Signal AS "1=↑, 2=↓")