Quick Fib

Category: Indicators By: Nicolas Created: January 9, 2019, 2:34 PM
January 9, 2019, 2:34 PM
Indicators
27 Comments

The Quick Fibonacci indicator plots automatically the Fibonacci retracement calculated with the last highest high and lowest low of the last X periods.

It adds on the price chart 2 trend lines:

  • ascending trendline starting from lowest low to second lowest price found
  • descending trendline starting from highest high to second highest price found

A “retracement block” can be also drawn by the indicator to indicate how much the price has retraced since the Fibonacci figure was formed.

The retracement lines change color depending of the trend:

  • green color if the price has retraced from a lowest low (price is ascending since longer)
  • red color if the price has retraced from a highest high (price is descending since longer)
//PRC_Quick Fib | indicator
//09.01.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge

defparam drawonlastbaronly = true

// --- settings 
period = 100 //lookback period of the Fibonacci Retracement 
DrawRetracementBlocks = 1 // 0=false ; 1=true
// --- 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)
 fibo100 = hh
 fibo0 = ll
 fibo236 = ll+(fullrange*0.236)
 fibo382 = ll+(fullrange*0.382)
 fibo50 = ll+fullrange/2
 fibo618 = ll+(fullrange*0.618)
 startbar = min(shifthighest,shiftlowest)
 r=255
 g=0
 b=0
else
 fullrange = abs(hh-ll)
 fibo100 = ll
 fibo0 = hh
 fibo236 = hh-(fullrange*0.236)
 fibo382 = hh-(fullrange*0.382)
 fibo50 = hh-fullrange/2
 fibo618 = hh-(fullrange*0.618)
 startbar = min(shifthighest,shiftlowest)
 r=0
 g=255
 b=0
endif

if startbar>0 then
 //plot fibonacci levels
 drawsegment(startbar,fibo100,barindex,fibo100) coloured(r,g,b)
 drawtext("          100%",barindex,fibo100,Dialog,Standard,20) coloured(r,g,b)
 drawsegment(startbar,fibo0,barindex,fibo0) coloured(r,g,b)
 drawtext("          0%",barindex,fibo0,Dialog,Standard,20) coloured(r,g,b)
 drawsegment(startbar,fibo236,barindex,fibo236) coloured(r,g,b)
 drawtext("          23.6%",barindex,fibo236,Dialog,Standard,20) coloured(r,g,b)
 drawsegment(startbar,fibo382,barindex,fibo382) coloured(r,g,b)
 drawtext("          38.2%",barindex,fibo382,Dialog,Standard,20) coloured(r,g,b)
 drawsegment(startbar,fibo50,barindex,fibo50) coloured(r,g,b)
 drawtext("          50%",barindex,fibo50,Dialog,Standard,20) coloured(r,g,b)
 drawsegment(startbar,fibo618,barindex,fibo618) coloured(r,g,b)
 drawtext("          61.8%",barindex,fibo618,Dialog,Standard,20) coloured(r,g,b)
 //plot price at 0% and 100% levels
 drawtext("#ll#",shiftlowest,ll-fullrange*0.03,dialog,standard,20) coloured(0,255,0)
 drawtext("#hh#",shifthighest,hh+fullrange*0.03,dialog,standard,20) coloured(255,0,0)
endif

//contour lines
shiftContourDown = barindex-shiftHighest
highestSlope = 0
counth=max(1,(barindex-shifthighest))
for i = 2 to counth do
 thisSlope = (High[i] - hh) / ((barindex-shiftHighest) - i)

 if (thisSlope >= highestSlope or highestSlope = 0) then
  shiftContourDown = i
  highestSlope = thisSlope
 endif
next
shiftContourUp = barindex-shiftLowest
LowestSlope = 0
countl=max(1,(barindex-shiftLowest))
for i = 2 to countl do
 thisSlope = (low[i] - ll) / ((barindex-shiftLowest) - i)

 if (thisSlope <= LowestSlope or LowestSlope = 0) then
  shiftContourUp = i
  LowestSlope = thisSlope
 endif
next
drawline(shifthighest,hh,barindex[shiftcontourdown],high[shiftcontourdown]) coloured(r,g,b)
drawline(shiftlowest,ll,barindex[shiftcontourup],low[shiftcontourup]) coloured(r,g,b)

//retracement blocks
if DrawRetracementBlocks then 
 if not isSwingDown then 
  blockprice=hh
  startbar=barindex-shifthighest
  for i = startbar downto 2 do
   if low[i]<blockprice then
    blockprice=low[i]
    blockbar=barindex[i]
   endif
  next
  drawrectangle(blockbar,blockprice,barindex,ll) coloured(r,g,b)
 else
  blockprice=ll
  startbar=barindex-shiftlowest
  for i = startbar downto 2 do
   if high[i]>blockprice then
    blockprice=high[i]
    blockbar=barindex[i]
   endif
  next
  drawrectangle(blockbar,blockprice,barindex,hh) coloured(r,g,b)
 endif

endif

return

 

Download
Filename: PRC_QuickFib.itf
Downloads: 538
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Logo Logo
Loading...