I have taken the Pattern Armonici ABCD code and modified it to work with an ABCD pattern that I have been working with on MT4, (hate MT4). I am not a coder, but I can be dangerous. I have re-worked the logic such that the Fib levels go from 0% to 200%, which have been coloured coded.
I am now looking to expand the functionality to include the next letter “C” and subsequently the letter “D”.
I am using the current allocation of “A” and “B” as per the code. I would like to now add point “C”, where it is the next low point or high point after point “B” which should be anywhere between 38.7% and 78.6% Fib levels. Point “D” would then be projected above or below the 100% Fib level into the corresponding colour Zone. I would include a 2-5% tolerance with point “C” in determining a Fib level to project above or below the 100% level in establishing the Point D.
Finally once point “C” is determined then point “D” would be a projection into the Fib level greater than 100% into the corresponding colour, eg. yellow to yellow, orange to orange, and red to red. I am not concerned about the purple zone or the grey zone above.
I am sure that my code could be greatly improved upon, and any suggestions would be greatly appreciated. For now I am looking for help to establish point “C” and subsequently point “D”.
Many thanks in advance.
Here is the code:
//PRC_Quick Fib | indicator
//09.01.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
defparam drawonlastbaronly = true
// --- settings
period = period //lookback period of the Fibonacci Retracement
DrawRetracementBlocks = 1 // 0=false ; 1=true
//Drawrectangle = 1
// --- end of settings
hh=0
ll=low
shiftlowest=barindex
fibext = FibExt
labeloffset = LabelOffset
Fill = Colours
Text = FibLevels
Levels = ChartLevels
//FibLabel= startbar + fibext
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 = ll
fibo0 = hh
fibo236 = hh-(fullrange*0.236)
fibo382 = hh-(fullrange*0.382)
fibo50 = hh-fullrange/2
fibo618 = hh-(fullrange*0.618)
fibo70 = hh-(fullrange*0.700)
fibo786 = hh-(fullrange*0.786)
fibo886 = hh-(fullrange*0.886)
fibo118 = hh-(fullrange*1.18)
fibo1272 = hh-(fullrange*1.272)
fibo144 = hh-(fullrange*1.44)
fibo1618 = hh-(fullrange*1.618)
fibo200 = hh-(fullrange*2.00)
startbar = min(shifthighest,shiftlowest)
r=255
g=0
b=0
else
fullrange = abs(hh-ll)
fibo100 = hh
fibo0 = ll
fibo236 = ll+(fullrange*0.236)
fibo382 = ll+(fullrange*0.382)
fibo50 = hh-fullrange/2
fibo618 = ll+(fullrange*0.618)
fibo70 = ll+(fullrange*0.700)
fibo786 = ll+(fullrange*0.786)
fibo886 = ll+(fullrange*0.886)
fibo118 = ll+(fullrange*1.18)
fibo1272 = ll+(fullrange*1.272)
fibo144 = ll+(fullrange*1.44)
fibo1618 = ll+(fullrange*1.618)
fibo200 = ll+(fullrange*2.00)
startbar = min(shifthighest,shiftlowest)
r=0
g=255
b=0
endif
if startbar>0 then
//plot fibonacci levels
drawsegment(startbar + 2,fibo100,startbar + fibext,fibo100) coloured(0,0,0) style(dottedline,2)
if text = 1 then
drawtext("100.0%",Startbar + fibext + labeloffset,fibo100,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#hh#",Startbar + fibext + labeloffset +8,fibo100,Dialog,Standard,10) coloured(0,0,0)
endif
if Fill =1 then
drawrectangle(startbar + 2, fibo100, startbar + fibext, fibo118) coloured(255,255,0,80) bordercolor(255,255,255,0)
endif
drawsegment(startbar +2,fibo0,startbar + fibext,fibo0) coloured(0,0,0) style(dottedline,2)
if Fill =1 then
drawrectangle(startbar + 2, fibo0, startbar + fibext, fibo382) coloured(224,224,224,80) bordercolor(255,255,255,0)
endif
if text = 1 then
drawtext(" 0.0%",Startbar + fibext + labeloffset,fibo0,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#ll#",Startbar + fibext + labeloffset +8,fibo0,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo236,startbar + fibext,fibo236) coloured(128,128,128)
if text = 1 then
drawtext(" 23.6%",Startbar + fibext + labeloffset,fibo236,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo236#",Startbar + fibext + labeloffset +8,fibo236,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo382,startbar + fibext,fibo382) coloured(255,255,0,0)
if Fill =1 then
drawrectangle(startbar + 2, fibo382, startbar + fibext, fibo50) coloured(255,255,0,80) bordercolor(255,255,255,0)
endif
if text = 1 then
drawtext(" 38.2%",Startbar + fibext + labeloffset,fibo382,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo382#",Startbar + fibext + labeloffset +8,fibo382,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo50,startbar + fibext,fibo50) coloured(153,0,0)
if Fill =1 then
drawrectangle(startbar + 2, fibo50, startbar + fibext, fibo70) coloured(153,0,0,80) bordercolor(255,255,255,0)
endif
if text = 1 then
drawtext(" 50.0%",Startbar + fibext + labeloffset,fibo50,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo50#",Startbar + fibext + labeloffset +8,fibo50,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo618,startbar + fibext,fibo618) coloured(153,0,0)
//drawrectangle(startbar + 2, fibo618, startbar + fibext, fibo786) coloured(153,0,0,80) bordercolor(255,255,255,0)
if text = 1 then
drawtext("61.8%",Startbar + fibext + labeloffset,fibo618,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo618#",Startbar + fibext + labeloffset+8,fibo618,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo70,startbar + fibext,fibo70) coloured(255,128,0)
if Fill =1 then
drawrectangle(startbar + 2, fibo70, startbar + fibext, fibo786) coloured(255,128,0,80) bordercolor(255,255,255,0)
endif
if text = 1 then
drawtext("70.0%",Startbar + fibext +labeloffset,fibo70,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo70#",Startbar + fibext + labeloffset +8,fibo70,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo786,startbar + fibext,fibo786) coloured(160,160,160)
if Fill =1 then
drawrectangle(startbar + 2, fibo786, startbar + fibext, fibo100) coloured(160,160,160,80) bordercolor(255,255,255,0)
endif
if text = 1 then
drawtext("78.6%",Startbar + fibext + labeloffset,fibo786,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo786#",Startbar + fibext + labeloffset +8,fibo786,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo886,startbar + fibext,fibo886) coloured(128,128,128)
//drawrectangle(startbar + 2, fibo886, startbar + fibext, fibo100) coloured(153,153,0,80) bordercolor(255,255,255,0)
if text = 1 then
drawtext("88.6%",Startbar + fibext + labeloffset,fibo886,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo886#",Startbar + fibext + labeloffset +8,fibo886,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo118,startbar + fibext,fibo118) coloured(255,128,0)
if Fill =1 then
drawrectangle(startbar + 2, fibo118, startbar + fibext, fibo1272) coloured(255,128,0,80)bordercolor(255,255,255,0)
endif
if text = 1 then
drawtext("118.0%",Startbar + fibext + labeloffset,fibo118,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo118#",Startbar + fibext + labeloffset +8,fibo118,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo1272,startbar + fibext,fibo1272) coloured(153,0,0)
if Fill =1 then
drawrectangle(startbar + 2, fibo1272, startbar + fibext, fibo144) coloured(153,0,0,80) bordercolor(255,255,255,0)
endif
if text = 1 then
drawtext("127.2%",Startbar + fibext + labeloffset,fibo1272,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo1272#",Startbar + fibext + labeloffset +8,fibo1272,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo144,startbar + fibext,fibo144) coloured(153,0,153)
if Fill =1 then
drawrectangle(startbar + 2, fibo144, startbar + fibext, fibo1618) coloured(153,0,153,80) bordercolor(255,255,255,0)
endif
if text = 1 then
drawtext("144.0%",Startbar + fibext + labeloffset,fibo144,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo144#",Startbar + fibext + labeloffset +8,fibo144,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo1618,startbar + fibext,fibo1618) coloured(204,229,255)
if Fill =1 then
drawrectangle(startbar + 2, fibo1618, startbar + fibext, fibo200) coloured(204,229,255,80) bordercolor(255,255,255,0)
endif
if text = 1 then
drawtext("161.8%",Startbar + fibext + labeloffset,fibo1618,Dialog,Standard,10) coloured(0,0,0)
endif
if levels = 1 then
drawtext("#fibo1618#",Startbar + fibext + labeloffset +8,fibo1618,Dialog,Standard,10) coloured(0,0,0)
endif
drawsegment(startbar +2,fibo200,startbar + fibext,fibo200) coloured(0,0,0) style(dottedline, 2)
if text = 1 then
drawtext("200.0%",Startbar + fibext + labeloffset,fibo200,Dialog,Standard,10) coloured(0,0,0)
if levels = 1 then
drawtext("#fibo200#",Startbar + fibext + labeloffset +8,fibo200,Dialog,Standard,10) coloured(0,0,0)
endif
endif
//plot price at 0% and 100% levels
if fibo0=ll then
drawtext("A",shiftlowest,ll-fullrange*0.03,dialog,bold,15) coloured(r,g,b)
else
drawtext("B",shiftlowest,ll-fullrange*0.03,dialog,bold,15) coloured(r,g,b)
endif
//drawtext("#ll#",shiftlowest,ll-fullrange*0.03,dialog,bold,15) coloured(0,255,0)
if fibo0=hh then
drawtext("A",shifthighest,hh+fullrange*0.03,dialog,bold,15) coloured(r,g,b)
else
drawtext("B",shifthighest,hh+fullrange*0.03,dialog,bold,15) coloured(r,g,b)
endif
//drawtext("#hh#",shiftlowest,ll-fullrange*0.03,dialog,bold,15) coloured(0,255,0)
endif
if fibo0=ll then
drawsegment(Startbar, fibo0, shifthighest, hh) coloured(0,0,255) style(dottedline, 2)
else
if fibo0=hh then
drawsegment(Startbar, fibo0, shiftlowest, ll) coloured(0,0,255) style(dottedline, 2)
endif
endif
//if fibo0 =1 and fibo0=ll then
//drawsegment( shifthightes, hh,
//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