defparam drawonlastbaronly = true
// --- settings
period = 200 //lookback period of the Fibonacci Retracement
// --- end of settings
hh=0
ll=low
shiftlowest=barindex
for i = period downto 1 do
if high[i]>hh then
hh=high[i]
shifthighest=barindex[i]
endif
if low[i]<ll then
ll=low[i]
shiftlowest=barindex[i]
endif
next
isSwingDown = shiftHighest < shiftLowest
if isSwingDown then
fullrange = abs(hh-ll)
rr1 = hh
ss1 = ll
startbar = min(shifthighest,shiftlowest)
else
fullrange = abs(hh-ll)
ss1 = ll
rr1 = hh
startbar = min(shifthighest,shiftlowest)
endif
if startbar>0 then
//plot fibonacci levels
drawsegment(shiftlowest,ss1,barindex,ss1) coloured(0,0,255)
drawtext(" Support = #ss1#",barindex-0,ss1+0*pipsize,Dialog,Standard,10) coloured(0,0,255)
drawsegment(shifthighest,rr1,barindex,rr1) coloured(255,0,0)
drawtext(" Résistance = #rr1#",barindex,rr1+0*pipsize,Dialog,Standard,10) coloured(255,0,0)
//plot price at 0% and 100% levels
drawtext("F= = #ll#",shiftlowest,ll-fullrange*0.04,dialog,standard,10) coloured(0,0,255)
drawtext("F = #hh#",shifthighest,hh+fullrange*0.04,dialog,standard,10) coloured(255,0,0)
endif
return