defparam drawonlastbaronly = true
atr=ROUND((AverageTrueRange[20](close)[1]),3)
TF = GetTimeFrame
IF TF = 86400 THEN // Day
upperlvl = floor(dlow(0)+atr,decimals)
lowerlvl = floor(dhigh(0)-atr,decimals)
drawsegment(barindex,upperlvl,barindex+3,upperlvl) style(dottedline,2)
drawsegment(barindex,lowerlvl,barindex+3,lowerlvl) style(dottedline,2)
drawtext("#upperlvl#",barindex+6,upperlvl, Dialog,Standard,10)
drawtext("#lowerlvl# #atr#" ,barindex+7,lowerlvl, Dialog,Standard ,10)
ColorBetween (upperlvl,lowerlvl,255,0,0,50)
ENDIF
IF TF = 604800 THEN // Week
upperlvl = floor(dlow(0)+atr,decimals)
lowerlvl = floor(dhigh(0)-atr,decimals)
drawsegment(barindex,upperlvl,barindex+3,upperlvl) style(dottedline,2)
drawsegment(barindex,lowerlvl,barindex+3,lowerlvl) style(dottedline,2)
drawtext("#upperlvl#",barindex+7,upperlvl, Dialog,Standard,10)
drawtext("#lowerlvl# #atr#" ,barindex+8,lowerlvl, Dialog,Standard,10)
drawtext("#lowerlvl# #atr#" ,barindex+7,lowerlvl, Dialog,Standard ,10)
ColorBetween (upperlvl,lowerlvl,255,0,0,50)
ENDIF
return