Le code ci-dessous trace les lignes de trendline sur l’indicateur RSI. On peut changer l’indicateur avec n’importe quel autre dans la variable “source”.
defparam drawonlastbaronly = true
defparam calculateonlastbars = 500
lookback = 20
showSR = 0
source = rsi[14]
//fractals
cp = lookback
if source[cp] >= highest[(cp)*2+1](source) then
LLH = 1
else
LLH = 0
endif
if source[cp] <= lowest[(cp)*2+1](source) then
LLL = -1
else
LLL = 0
endif
if LLH = 1 then
oldLTOPy = LTOPy[1]
oldLTOPx = LTOPx[1]
LTOPy = source[cp]
LTOPx = barindex[cp]
endif
if LLL = -1 then
oldLBOTy = LBOTy[1]
oldLBOTx = LBOTx[1]
LBOTy = source[cp]
LBOTx = barindex[cp]
endif
//trend line
DRAWLINE(oldLTOPx,oldLTOPy,LTOPx,LTOPy)coloured(112,169,161)
DRAWLINE(oldLBOTx,oldLBOTy,LBOTx,LBOTy)coloured(211,78,36)
//support/resistance
if showSR then
DRAWHLINE(LTOPy) COLOURED(207,215,199,100)
DRAWHLINE(LBOTy) COLOURED(207,215,199,100)
endif
barelapsedTOP=barindex-LTOPX
barelapsedBOTTOM=barindex-LBOTX
factorTOP = (LTOPy-oldLTOPy)/(LTOPx-oldLTOPx)
factorBOTTOM = (LBOTy-oldLBOTy)/(LBOTx-oldLBOTx)
//drawtext("#factor#",barindex,low-10*pipsize,Dialog,Bold,20)
nowTOP = LTOPy+(barelapsedTOP*factorTOP)
drawtext("X",barindex,nowTOP,Dialog,Bold,20) coloured(112,169,161)
nowBOTTOM = LBOTy+(barelapsedBOTTOM*factorBOTTOM)
drawtext("X",barindex,nowBOTTOM,Dialog,Bold,20) coloured(211,78,36)
RETURN source as "indicator", nowTOP coloured(110,0,0,0), nowBOTTOM coloured(110,0,0,0)