Divergences and hidden divergences toolbox

Category: Indicators By: jacquesgermain Created: November 28, 2023, 8:35 AM
November 28, 2023, 8:35 AM
Indicators
0 Comments

Divergences and hidden divergences toolbox

This indicator displays the following discrepancies and hidden discrepancies:

macd,rsi,mfi,obv,cci,sto,pvt

////////////////////////////////////////////////////////////////////////////////////////////

/*variables
divmacd=t ou f
divrsi=t ou f
divmfi=t ou f
divobv=t ou f
divcci=t ou f
divsto=t ou f
divpvt=t ou f
baissière=t ou f
cache=t ou f
*/

Defparam CALCULATEONLASTBARS=300
if close>open then
newclose=close
newopen=open
endif
if close<= open then
newclose=open
newopen=close
endif
N=40
miMACD=MACDline[9,19,6](typicalprice)
flag=0
signalmacd=0
IF (miMACD[1]>miMACD AND miMACD[1]>miMACD[2]) THEN
macdextrem2=miMACD[1]
macdextrem1=highest[N](miMACD)
macdpmax2=close[1]
macdpmax=Highest[N](close)
IF(macdextrem2<macdextrem1 AND macdpmax2>macdpmax[1]) THEN
for macdi=1 to N
if close[macdi]=macdpmax[1] and baissiere and divmacd then
macdzzm=macdi
if newclose[1]>newclose[macdzzm] then
signalmacd=-1
flag=1
drawsegment (barindex[1], newclose[1], barindex[macdzzm],newclose[macdzzm]) coloured(0,0,0)style(dottedline,2)
endif
endif
next
endif
endif
IF (miMACD[1]>miMACD AND miMACD[1]>miMACD[2]) THEN
macdextremB2=miMACD[1]
macdextremB1=highest[N](miMACD)
macdpmaxB2=close[1]
macdpmaxB=Highest[N](close)
IF(macdextremB2=macdextremB1 AND macdpmaxB2>macdpmaxB[1]) THEN
for macdk=1 to N
if close[macdk]=macdpmaxB[1] and baissiere and divmacd and cache then
macdzzmB=macdk
if newclose[1]<newclose[macdzzmB] then
signalmacd=-2
flag=1
drawsegment (barindex[1], newclose[1], barindex[macdzzmB],newclose[macdzzmB]) coloured(0,0,0)style(dottedline,1)
endif
endif
next
endif
endif
IF (miMACD[1]<miMACD AND miMACD[1]<miMACD[2]) THEN
macdextrem22=miMACD[1]
macdextrem11=lowest[N](miMACD)
macdpmin2=close[1]
macdpmin=lowest[N](close)
IF(macdextrem22>macdextrem11 AND macdpmin2<macdpmin[1]) THEN
for macdj2=1 to N
if close[macdj2]=macdpmin[1] and divmacd then
macdzzm2=macdj2
if newopen[1]<newopen[macdzzm2] then
signalmacd=1
flag=1
drawsegment(barindex[1],newopen[1], barindex[macdzzm2], newopen[macdzzm2]) coloured(0,0,0)style(line,2)
endif
endif
next
endif
endif
IF (miMACD[1]<miMACD AND miMACD[1]<miMACD[2]) THEN
macdextremC2=miMACD[1]
macdextremC1=lowest[N](miMACD)
macdpminC2=close[1]
macdpminC=Lowest[N](close)
IF(macdextremC2=macdextremC1 AND macdpminC2>macdpminC[1]) THEN
for macdl=1 to N
if close[macdl]=macdpminC[1] and divmacd and cache then
macdzzmC=macdl
if newopen[1]>newopen[macdzzmC] then
signalmacd=2
flag=1
drawsegment (barindex[1], newopen[1], barindex[macdzzmC],newopen[macdzzmC]) coloured(0,0,0)style(line,1)
endif
endif
next
endif
endif
miRSI=RSI[14](close)
lowrsi=30 //oversold level
highrsi=70 //overbought level
signalrsi=0
IF (mirsi[1]>mirsi AND mirsi[1]>mirsi[2]) THEN
rsiextrem2=mirsi[1]
rsiextrem1=highest[N](mirsi)
rsipmax2=close[1]
rsipmax=Highest[N](close)
IF(rsiextrem2<rsiextrem1 AND rsipmax2>rsipmax[1]) THEN
for rsii=1 to N
if close[rsii]=rsipmax[1] and baissiere and divrsi then
rsizzm=rsii
if newclose[1]>newclose[rsizzm] then
signalrsi=-1
flag=1
drawsegment (barindex[1], newclose[1], barindex[rsizzm],newclose[rsizzm]) coloured(150,0,0)style(dottedline,2)
endif
endif
next
endif
endif
IF (mirsi[1]>mirsi AND mirsi[1]>mirsi[2]) THEN
rsiextremB2=mirsi[1]
rsiextremB1=highest[N](mirsi)
rsipmaxB2=close[1]
rsipmaxB=Highest[N](close)
IF(rsiextremB2=rsiextremB1 AND rsipmaxB2>rsipmaxB[1]) THEN
for rsik=1 to N
if close[rsik]=rsipmaxB[1] and baissiere and divrsi and cache then
rsizzmB=rsik
if newclose[1]<newclose[rsizzmB] then
signalrsi=-2
flag=1
drawsegment (barindex[1], newclose[1], barindex[rsizzmB],newclose[rsizzmB]) coloured(150,0,0)style(dottedline,1)
endif
endif
next
endif
endif
IF (mirsi[1]<mirsi AND mirsi[1]<mirsi[2]) THEN
rsiextrem22=mirsi[1]
rsiextrem11=lowest[N](mirsi)
rsipmin2=close[1]
rsipmin=lowest[N](close)
IF(rsiextrem22>rsiextrem11 AND rsipmin2<rsipmin[1]) THEN
for rsij2=1 to N
if close[rsij2]=rsipmin[1] and divrsi then
rsizzm2=rsij2
if newopen[1]<newopen[rsizzm2] then
signalrsi=1
flag=1
drawsegment(barindex[1],newopen[1], barindex[rsizzm2], newopen[rsizzm2]) coloured(150,0,0)style(line,2)
endif
endif
next
endif
endif
IF (mirsi[1]<mirsi AND mirsi[1]<mirsi[2]) THEN
rsiextremC2=mirsi[1]
rsiextremC1=lowest[N](mirsi)
rsipminC2=close[1]
rsipminC=Lowest[N](close)
IF(rsiextremC2=rsiextremC1 AND rsipminC2>rsipminC[1]) THEN
for rsil=1 to N
if close[rsil]=rsipminC[1] and divrsi and cache then
rsizzmC=rsil
if newopen[1]>newopen[rsizzmC] then
signalrsi=2
flag=1
drawsegment (barindex[1], newopen[1], barindex[rsizzmC],newopen[rsizzmC]) coloured(150,0,0)style(line,1)
endif
endif
next
endif
endif
miMFI=MoneyFlowIndex[14]
lowmfi=20 //oversold level
highmfi=80 //overbought level
signalMFI=0
IF (miMFI[1]>miMFI AND miMFI[1]>miMFI[2]) THEN
MFIextrem2=miMFI[1]
MFIextrem1=highest[N](miMFI)
MFIpmax2=close[1]
MFIpmax=Highest[N](close)
IF(MFIextrem2<MFIextrem1 AND MFIpmax2>MFIpmax[1]) THEN
for MFIi=1 to N
if close[MFIi]=MFIpmax[1] and baissiere and divMFI and mimfi>=highmfi then
MFIzzm=MFIi
if newclose[1]>newclose[MFIzzm] then
signalMFI=-1
flag=1
drawsegment (barindex[1], newclose[1], barindex[MFIzzm],newclose[MFIzzm]) coloured(0,150,0)style(dottedline,2)
endif
endif
next
endif
endif
IF (miMFI[1]>miMFI AND miMFI[1]>miMFI[2]) THEN
MFIextremB2=miMFI[1]
MFIextremB1=highest[N](miMFI)
MFIpmaxB2=close[1]
MFIpmaxB=Highest[N](close)
IF(MFIextremB2=MFIextremB1 AND MFIpmaxB2>MFIpmaxB[1]) THEN
for MFIk=1 to N
if close[MFIk]=MFIpmaxB[1] and baissiere and divMFI and cache and mimfi>=highmfi then
MFIzzmB=MFIk
if newclose[1]<newclose[MFIzzmB] then
signalMFI=-2
flag=1
drawsegment (barindex[1], newclose[1], barindex[MFIzzmB],newclose[MFIzzmB]) coloured(0,150,0)style(dottedline,1)
endif
endif
next
endif
endif
IF (miMFI[1]<miMFI AND miMFI[1]<miMFI[2]) THEN
MFIextrem22=miMFI[1]
MFIextrem11=lowest[N](miMFI)
MFIpmin2=close[1]
MFIpmin=lowest[N](close)
IF(MFIextrem22>MFIextrem11 AND MFIpmin2<MFIpmin[1]) THEN
for MFIj2=1 to N
if close[MFIj2]=MFIpmin[1] and divMFI and mimfi<=lowmfi then
MFIzzm2=MFIj2
if newopen[1]<newopen[MFIzzm2] then
signalMFI=1
flag=1
drawsegment(barindex[1],newopen[1], barindex[MFIzzm2], newopen[MFIzzm2]) coloured(0,150,0)style(line,2)
endif
ENDIF
next
endif
endif
IF (miMFI[1]<miMFI AND miMFI[1]<miMFI[2]) THEN
MFIextremC2=miMFI[1]
MFIextremC1=lowest[N](miMFI)
MFIpminC2=close[1]
MFIpminC=Lowest[N](close)
IF(MFIextremC2=MFIextremC1 AND MFIpminC2>MFIpminC[1]) THEN
for MFIl=1 to N
if close[MFIl]=MFIpminC[1] and divMFI and cache and mimfi<=lowmfi then
MFIzzmC=MFIl
if newopen[1]>newopen[MFIzzmC] then
signalMFI=2
flag=1
drawsegment (barindex[1], newopen[1], barindex[MFIzzmC],newopen[MFIzzmC]) coloured(0,150,0)style(line,1)
endif
ENDIF
next
endif
endif
miOBV=OBV(close)
signalOBV=0
IF (miOBV[1]>miOBV AND miOBV[1]>miOBV[2]) THEN
OBVextrem2=miOBV[1]
OBVextrem1=highest[N](miOBV)
OBVpmax2=close[1]
OBVpmax=Highest[N](close)
IF(OBVextrem2<OBVextrem1 AND OBVpmax2>OBVpmax[1]) THEN
for OBVi=1 to N
if close[OBVi]=OBVpmax[1] and baissiere and divOBV then
OBVzzm=OBVi
if newclose[1]>newclose[OBVzzm] then
signalOBV=-1
flag=1
drawsegment (barindex[1], newclose[1], barindex[OBVzzm],newclose[OBVzzm]) coloured(0,0,150)style(dottedline,2)
endif
endif
next
endif
endif
IF (miOBV[1]>miOBV AND miOBV[1]>miOBV[2]) THEN
OBVextremB2=miOBV[1]
OBVextremB1=highest[N](miOBV)
OBVpmaxB2=close[1]
OBVpmaxB=Highest[N](close)
IF(OBVextremB2=OBVextremB1 AND OBVpmaxB2>OBVpmaxB[1]) THEN
for OBVk=1 to N
if close[OBVk]=OBVpmaxB[1] and baissiere and divOBV and cache then
OBVzzmB=OBVk
if newclose[1]<newclose[OBVzzmB] then
signalOBV=-2
flag=1
drawsegment (barindex[1], newclose[1], barindex[OBVzzmB],newclose[OBVzzmB]) coloured(0,0,150)style(dottedline,1)
endif
endif
next
endif
endif
IF (miOBV[1]<miOBV AND miOBV[1]<miOBV[2]) THEN
OBVextrem22=miOBV[1]
OBVextrem11=lowest[N](miOBV)
OBVpmin2=close[1]
OBVpmin=lowest[N](close)
IF(OBVextrem22>OBVextrem11 AND OBVpmin2<OBVpmin[1]) THEN
for OBVj2=1 to N
if close[OBVj2]=OBVpmin[1] and divOBV then
OBVzzm2=OBVj2
if newopen[1]<newopen[OBVzzm2] then
signalOBV=1
flag=1
drawsegment(barindex[1],newopen[1], barindex[OBVzzm2], newopen[OBVzzm2]) coloured(0,0,150)style(line,2)
endif
endif
next
endif
endif
IF (miOBV[1]<miOBV AND miOBV[1]<miOBV[2]) THEN
OBVextremC2=miOBV[1]
OBVextremC1=lowest[N](miOBV)
OBVpminC2=close[1]
OBVpminC=Lowest[N](close)
IF(OBVextremC2=OBVextremC1 AND OBVpminC2>OBVpminC[1]) THEN
for OBVl=1 to N
if close[OBVl]=OBVpminC[1] and divOBV and cache then
OBVzzmC=OBVl
if newopen[1]>newopen[OBVzzmC] then
signalOBV=2
flag=1
drawsegment (barindex[1], newopen[1], barindex[OBVzzmC],newopen[OBVzzmC]) coloured(0,0,150)style(line,1)
endif
endif
next
endif
endif
highcci=100 //overbought level
lowcci=-100 //oversold level
miCCI=CCI[20](typicalPrice)
signalCCI=0
IF (miCCI[1]>miCCI AND miCCI[1]>miCCI[2]) THEN
CCIextrem2=miCCI[1]
CCIextrem1=highest[N](miCCI)
CCIpmax2=close[1]
CCIpmax=Highest[N](close)
IF(CCIextrem2<CCIextrem1 AND CCIpmax2>CCIpmax[1]) THEN
for CCIi=1 to N
if close[CCIi]=CCIpmax[1] and baissiere and divCCI and miCCI >=highcci then
CCIzzm=CCIi
if newclose[1]>newclose[CCIzzm] then
signalCCI=-1
flag=1
drawsegment (barindex[1], newclose[1], barindex[CCIzzm],newclose[CCIzzm]) coloured(225,150,0)style(dottedline,2)
endif
endif
next
endif
endif
IF (miCCI[1]>miCCI AND miCCI[1]>miCCI[2]) THEN
CCIextremB2=miCCI[1]
CCIextremB1=highest[N](miCCI)
CCIpmaxB2=close[1]
CCIpmaxB=Highest[N](close)
IF(CCIextremB2=CCIextremB1 AND CCIpmaxB2>CCIpmaxB[1]) THEN
for CCIk=1 to N
if close[CCIk]=CCIpmaxB[1] and baissiere and divCCI and cache and miCCI >=highcci then
CCIzzmB=CCIk
if newclose[1]<newclose[CCIzzmB] then
signalCCI=-2
flag=1
drawsegment (barindex[1], newclose[1], barindex[CCIzzmB],newclose[CCIzzmB]) coloured(225,150,0)style(dottedline,1)
endif
endif
next
endif
endif
IF (miCCI[1]<miCCI AND miCCI[1]<miCCI[2]) THEN
CCIextrem22=miCCI[1]
CCIextrem11=lowest[N](miCCI)
CCIpmin2=close[1]
CCIpmin=lowest[N](close)
IF(CCIextrem22>CCIextrem11 AND CCIpmin2<CCIpmin[1]) THEN
for CCIj2=1 to N
if close[CCIj2]=CCIpmin[1] and divCCI and miCCI <=lowcci then
CCIzzm2=CCIj2
if newopen[1]<newopen[CCIzzm2] then
signalCCI=1
flag=1
drawsegment(barindex[1],newopen[1], barindex[CCIzzm2], newopen[CCIzzm2]) coloured(225,150,0)style(line,2)
endif
endif
next
endif
endif
IF (miCCI[1]<miCCI AND miCCI[1]<miCCI[2]) THEN
CCIextremC2=miCCI[1]
CCIextremC1=lowest[N](miCCI)
CCIpminC2=close[1]
CCIpminC=Lowest[N](close)
IF(CCIextremC2=CCIextremC1 AND CCIpminC2>CCIpminC[1]) THEN
for CCIl=1 to N
if close[CCIl]=CCIpminC[1] and divCCI and cache and miCCI <=lowcci then
CCIzzmC=CCIl
if newopen[1]>newopen[CCIzzmC] then
signalCCI=2
flag=1
drawsegment (barindex[1], newopen[1], barindex[CCIzzmC],newopen[CCIzzmC]) coloured(225,150,0)style(line,1)
endif
endif
next
endif
endif
lowsto=-40 //oversold level
highsto=40 //overbought level
miSTO = SMI[14,3,5](close)
signalSTO=0
IF (miSTO[1]>miSTO AND miSTO[1]>miSTO[2]) THEN
STOextrem2=miSTO[1]
STOextrem1=highest[N](miSTO)
STOpmax2=close[1]
STOpmax=Highest[N](close)
IF(STOextrem2<STOextrem1 AND STOpmax2>STOpmax[1]) THEN
for STOi=1 to N
if close[STOi]=STOpmax[1] and baissiere and divSTO and miSTO>=highsto then
STOzzm=STOi
if newclose[1]>newclose[STOzzm] then
signalSTO=-1
flag=1
drawsegment (barindex[1], newclose[1], barindex[STOzzm],newclose[STOzzm]) coloured(50,50,50)style(dottedline,2)
endif
endif
next
endif
endif
IF (miSTO[1]>miSTO AND miSTO[1]>miSTO[2]) THEN
STOextremB2=miSTO[1]
STOextremB1=highest[N](miSTO)
STOpmaxB2=close[1]
STOpmaxB=Highest[N](close)
IF(STOextremB2=STOextremB1 AND STOpmaxB2>STOpmaxB[1]) THEN
for STOk=1 to N
if close[STOk]=STOpmaxB[1] and baissiere and divSTO and cache and miSTO>=highsto then
STOzzmB=STOk
if newclose[1]<newclose[STOzzmB] then
signalSTO=-2
flag=1
drawsegment (barindex[1], newclose[1], barindex[STOzzmB],newclose[STOzzmB]) coloured(50,50,50)style(dottedline,1)
endif
endif
next
endif
endif
IF (miSTO[1]<miSTO AND miSTO[1]<miSTO[2]) THEN
STOextrem22=miSTO[1]
STOextrem11=lowest[N](miSTO)
STOpmin2=close[1]
STOpmin=lowest[N](close)
IF(STOextrem22>STOextrem11 AND STOpmin2<STOpmin[1]) THEN
for STOj2=1 to N
if close[STOj2]=STOpmin[1] and divSTO and miSTO<=lowsto then
STOzzm2=STOj2
if newopen[1]<newopen[STOzzm2] then
signalSTO=1
flag=1
drawsegment(barindex[1],newopen[1], barindex[STOzzm2], newopen[STOzzm2]) coloured(50,50,50)style(line,2)
endif
endif
next
endif
endif
IF (miSTO[1]<miSTO AND miSTO[1]<miSTO[2]) THEN
STOextremC2=miSTO[1]
STOextremC1=lowest[N](miSTO)
STOpminC2=close[1]
STOpminC=Lowest[N](close)
IF(STOextremC2=STOextremC1 AND STOpminC2>STOpminC[1]) THEN
for STOl=1 to N
if close[STOl]=STOpminC[1] and divSTO and cache and miSTO<=lowsto then
STOzzmC=STOl
if newopen[1]>newopen[STOzzmC] then
signalSTO=2
flag=1
drawsegment (barindex[1], newopen[1], barindex[STOzzmC],newopen[STOzzmC]) coloured(50,50,50)style(line,1)
endif
endif
next
endif
endif
miPVT=PVT(close)
signalPVT=0
IF (miPVT[1]>miPVT AND miPVT[1]>miPVT[2]) THEN
PVTextrem2=miPVT[1]
PVTextrem1=highest[N](miPVT)
PVTpmax2=close[1]
PVTpmax=Highest[N](close)
IF(PVTextrem2<PVTextrem1 AND PVTpmax2>PVTpmax[1]) THEN
for PVTi=1 to N
if close[PVTi]=PVTpmax[1] and baissiere and divPVT then
PVTzzm=PVTi
if newclose[1]>newclose[PVTzzm] then
signalPVT=-1
flag=1
drawsegment (barindex[1], newclose[1], barindex[PVTzzm],newclose[PVTzzm]) coloured(150,0,150)style(dottedline,2)
endif
endif
next
endif
endif
IF (miPVT[1]>miPVT AND miPVT[1]>miPVT[2]) THEN
PVTextremB2=miPVT[1]
PVTextremB1=highest[N](miPVT)
PVTpmaxB2=close[1]
PVTpmaxB=Highest[N](close)
IF(PVTextremB2=PVTextremB1 AND PVTpmaxB2>PVTpmaxB[1]) THEN
for PVTk=1 to N
if close[PVTk]=PVTpmaxB[1] and baissiere and divPVT and cache then
PVTzzmB=PVTk
if newclose[1]<newclose[PVTzzmB] then
signalPVT=-2
flag=1
drawsegment (barindex[1], newclose[1], barindex[PVTzzmB],newclose[PVTzzmB]) coloured(150,0,150)style(dottedline,1)
endif
endif
next
endif
endif
IF (miPVT[1]<miPVT AND miPVT[1]<miPVT[2]) THEN
PVTextrem22=miPVT[1]
PVTextrem11=lowest[N](miPVT)
PVTpmin2=close[1]
PVTpmin=lowest[N](close)
IF(PVTextrem22>PVTextrem11 AND PVTpmin2<PVTpmin[1]) THEN
for PVTj2=1 to N
if close[PVTj2]=PVTpmin[1] and divPVT then
PVTzzm2=PVTj2
if newopen[1]<newopen[PVTzzm2] then
signalPVT=1
flag=1
drawsegment(barindex[1],newopen[1], barindex[PVTzzm2], newopen[PVTzzm2]) coloured(150,0,150)style(line,2)
endif
endif
next
endif
endif
IF (miPVT[1]<miPVT AND miPVT[1]<miPVT[2]) THEN
PVTextremC2=miPVT[1]
PVTextremC1=lowest[N](miPVT)
PVTpminC2=close[1]
PVTpminC=Lowest[N](close)
IF(PVTextremC2=PVTextremC1 AND PVTpminC2>PVTpminC[1]) THEN
for PVTl=1 to N
if close[PVTl]=PVTpminC[1] and divPVT and cache then
PVTzzmC=PVTl
if newopen[1]>newopen[PVTzzmC] then
signalPVT=2
flag=1
drawsegment (barindex[1], newopen[1], barindex[PVTzzmC],newopen[PVTzzmC]) coloured(150,0,150)style(line,1)
endif
endif
next
endif
endif
if islastbarupdate then
DRAWTEXT("Noir:macd",-100,-20,dialog,standard,10)coloured(0,0,0)anchor(topright,xshift,yshift)
DRAWTEXT("Rouge:rsi",-100,-40,dialog,standard,10)coloured(150,0,0)anchor(topright,xshift,yshift)
DRAWTEXT("Vert:mfi",-100,-60,dialog,standard,10)coloured(0,150,0)anchor(topright,xshift,yshift)
DRAWTEXT("Bleu:obv",-100,-80,dialog,standard,10)coloured(0,0,150)anchor(topright,xshift,yshift)
DRAWTEXT("Orange:cci",-100,-100,dialog,standard,10)coloured(225,150,0)anchor(topright,xshift,yshift)
DRAWTEXT("Gris:sto",-100,-120,dialog,standard,10)coloured(50,50,50)anchor(topright,xshift,yshift)
DRAWTEXT("Violet:pvt",-100,-140,dialog,standard,10)coloured(150,0,150)anchor(topright,xshift,yshift)
endif
return

Download
Filename: divergences-and-hidden-div.itf
Downloads: 313
jacquesgermain Veteran
This author is like an anonymous function, present but not directly identifiable. More details on this code architect as soon as they exit 'incognito' mode.
Author’s Profile

Comments

Logo Logo
Loading...