This indicator add a trend line on chart accordingly to the CCI value. It also painting background charts to identify bearish and bullish trend.
// CCI Magic DID V1
cc = customclose
if (CCI[p](typicalPrice)>=0) then
magic=Low[0]-AverageTrueRange[p1](close)
endif
if (CCI[p](typicalPrice)<0) then
magic=High[0]+AverageTrueRange[p1](close)
endif
if (CCI[p](typicalPrice)>=0 and magic<magic[1]) then
magic=magic[1]
endif
if (CCI[50](typicalPrice)<0 and magic>magic[1]) then
magic=magic[1]
endif
hh = magic + coeff
bb = magic - coeff
////////////////////////////////////////////////
if cc > hh then
backgroundcolor(0,139,0) // vert foncé
endif
if cc > magic and cc < hh then
backgroundcolor(0,255,0) // vert clair
endif
if cc < magic and cc > bb then
backgroundcolor(255,0,255) // rose clair
endif
if cc < bb then
backgroundcolor(238,44,44) // rouge
endif
////////////////////////////////////////////////
return cc as " cc " , magic as " magic " , hh as " hh " , bb as " bb "
// Variables :
// p = 50 = periode CCI par défaut
// p1 = 5 = periode ATR par défaut
// coeff = 1 decimal