I was inspired by the “Another RSI Divergence Indicator by Nicolas. The same idee has applied to the SMI and to the CCI indicators.
OverboughtLevel are not 70 and 30 RSI but 40 and -40 for SMI and 100 and -100 for CCI.
And as you can see the RSI is replaced by the SMI and the CCI respectively.
// Settings for SMI Divergence
obLevel=40 //overbought level
osLevel=-40 //oversold level
minimalBars=5 //minimal count of bars where CCI is ob or os
// End of settings
iSMi =SMI[14,3,5](close)
ob = iSMi>obLevel
os = iSMi<osLevel
if ob then
if not ob[1] then
maxSMi = 0
maxprice = 0
firstobbar = barindex
endif
maxSMi=max(maxSMi,ISMI)
maxprice=max(maxprice,high)
if maxSMi<>maxSMi[1] then
maxSMibar=barindex
endif
endif
if os then
if not os[1] then
minSMi = 100
minprice = close*100
firstosbar = barindex
endif
minSMi=min(minSMi,ISMI)
minprice=min(minprice,low)
if minSMi<>minSMi[1] then
minSMibar=barindex
endif
endif
divsell=0
if ISMI crosses under obLevel then
//verif divergence
div = maxprice>oldmaxprice and maxSMi<oldmaxSMi and (barindex-firstobbar)>=minimalBars
if div then
drawsegment(oldmaxSMibar,oldmaxSMi,maxSMibar,maxSMi) coloured(200,0,0)
drawarrowdown(maxSMibar,maxSMi) coloured(200,0,0)
DRAWVLINE(barindex)coloured(200,120,0,255)
divsell=osLevel
endif
oldmaxSMi = maxSMi
oldmaxprice = maxprice
oldmaxSMibar = maxSMibar
endif
divbuy=0
if iSMI crosses over osLevel then
//verif divergence
div = minprice<oldminprice and minSMi>oldminSMi and (barindex-firstosbar)>=minimalBars
if div then
drawsegment(oldminSMibar,oldminSMi,minSMibar,minSMi) coloured(0,120,200)
drawarrowup(minSMibar,minSMi) coloured(0,120,200)
DRAWVLINE(barindex)coloured(0,120,200,255)
divbuy=osLevel
endif
oldminSMi = minSMi
oldminprice = minprice
oldminSMibar = minSMibar
endif
return iSMI style(line,2) as "SMI",obLevel coloured(168,168,168) style(dottedline,2) as "overbought level", osLevel coloured(168,168,168) style(dottedline,1) as "oversold level", divsell coloured(200,0,0), divbuy coloured(0,200,0)
// Settings for CCI Divergence
obLevel=40 //overbought level
osLevel=-40 //oversold level
minimalBars=5 //minimal count of bars where CCI is ob or os
// End of settings
iSMi =SMI[14,3,5](close)
ob = iSMi>obLevel
os = iSMi<osLevel
if ob then
if not ob[1] then
maxSMi = 0
maxprice = 0
firstobbar = barindex
endif
maxSMi=max(maxSMi,ISMI)
maxprice=max(maxprice,high)
if maxSMi<>maxSMi[1] then
maxSMibar=barindex
endif
endif
if os then
if not os[1] then
minSMi = 100
minprice = close*100
firstosbar = barindex
endif
minSMi=min(minSMi,ISMI)
minprice=min(minprice,low)
if minSMi<>minSMi[1] then
minSMibar=barindex
endif
endif
divsell=0
if ISMI crosses under obLevel then
//verif divergence
div = maxprice>oldmaxprice and maxSMi<oldmaxSMi and (barindex-firstobbar)>=minimalBars
if div then
drawsegment(oldmaxSMibar,oldmaxSMi,maxSMibar,maxSMi) coloured(200,0,0)
drawarrowdown(maxSMibar,maxSMi) coloured(200,0,0)
DRAWVLINE(barindex)coloured(200,120,0,255)
divsell=osLevel
endif
oldmaxSMi = maxSMi
oldmaxprice = maxprice
oldmaxSMibar = maxSMibar
endif
divbuy=0
if iSMI crosses over osLevel then
//verif divergence
div = minprice<oldminprice and minSMi>oldminSMi and (barindex-firstosbar)>=minimalBars
if div then
drawsegment(oldminSMibar,oldminSMi,minSMibar,minSMi) coloured(0,120,200)
drawarrowup(minSMibar,minSMi) coloured(0,120,200)
DRAWVLINE(barindex)coloured(0,120,200,255)
divbuy=osLevel
endif
oldminSMi = minSMi
oldminprice = minprice
oldminSMibar = minSMibar
endif
return iSMI style(line,2) as "SMI",obLevel coloured(168,168,168) style(dottedline,2) as "overbought level", osLevel coloured(168,168,168) style(dottedline,1) as "oversold level", divsell coloured(200,0,0), divbuy coloured(0,200,0)