//---Initialisation
Once init = 1
Once marge = 0.2 // 2% de marge d'erreur
If init = 1 then
For wl = 0 to 30 do
$Newlow[wl] = 0
$Newhigh[wl] = 0
$LastTurningPoint[wl] = 0
$Top1x[wl] = 0
$Top2x[wl] = 0
$Top3x[wl] = 0
$Bot1x[wl] = 0
$Bot2x[wl] = 0
$Bot3x[wl] = 0
Next
init = 0
Endif
//---Zigzag points detection
For wl = 5 to 21 do
//If wl = 14 then //wl = 7 or
ATR = averagetruerange[wl](close)
IF barindex >= 2*wl+1 then
if high[wl] >= highest[2*wl+1](high) and $LastTurningPoint[wl]<=0 and $Newlow[wl]=0 then
$NewHigh[wl] = 1
If $Top2x[wl] <> 0 then
$Top1x[wl] = $Top2x[wl]
Endif
If $Top3x[wl] <> 0 then
$Top2x[wl] = $Top3x[wl]
Endif
$Top3x[wl] = barindex[wl]
$LastTurningPoint[wl]= 1
else
$NewHigh[wl] = 0
endif
if low[wl] <= lowest[2*wl+1](low) and $LastTurningPoint[wl]>=0 and $NewHigh[wl]=0 then
$NewLow[wl] = 1
If $Bot2x[wl] <> 0 then
$Bot1x[wl] = $Bot2x[wl]
Endif
If $Bot3x[wl] <> 0 then
$Bot2x[wl] = $Bot3x[wl]
Endif
$Bot3x[wl] = barindex[wl]
$LastTurningPoint[wl]= -1
else
$NewLow[wl] = 0
endif
Endif
//endif
Next
//--- Gartley aka 222 pattern detection
For wl = 2 to 56 do
//If wl = 14 then //wl = 7 or
// A-t'on 4 points ?
If $Top2x[wl] <> 0 and $Bot2x[wl] <> 0 and (barindex-Max($Top3x[wl],$Bot3x[wl])) >= wl then
Delta = Close / 500 // Delta à 0.20%
If $Top2x[wl] > $Bot2x[wl] then
// Possible Gartley pattern haussier ?
PtxX = $Bot2x[wl]
PtyX = low[barindex-PtxX]
PtxA = $Top2x[wl]
PtyA = High[barindex-PtxA]
PtxB = $Bot3x[wl]
PtyB = low[barindex-PtxB]
PtxC = $Top3x[wl]
PtyC = High[barindex-PtxC]
XA = PtyA - PtyX
AB = PtyA - PtyB
BC = PtyC - PtyB
CD = PtyC - Low
If (AB >= XA*0.618*(1-marge) and AB <= XA*0.618*(1+marge)) and ((BC >= AB*0.382*(1-marge) and BC <= AB*0.382*(1+marge) and CD >= BC*1.272*(1-marge) and CD <= BC*1.272*(1+marge)) or (BC >= AB*0.886*(1-marge) and BC <= AB*0.886*(1+marge) and CD >= BC*1.618*(1-marge) and CD <= BC*1.618*(1+marge))) and (CD >= XA*0.786*(1-marge) and CD <= XA*0.786*(1+marge)) and PtyX = Lowest[PtxB-PtxX+1](Low[barindex-PtxB]) and Low = Lowest[Barindex-PtxB+1](Low) then
// 5ème point potentiel trouvé = Barindex
PtxD = Barindex
PtyD = Low
drawtriangle(PtxX,PtyX,PtxA,PtyA,PtxB,PtyB) coloured("deepskyblue",75) bordercolor("deepskyblue",200)
drawtriangle(PtxB,PtyB,PtxC,PtyC,PtxD,PtyD) coloured("deepskyblue",150) bordercolor("deepskyblue",200)
Endif
Endif
If $Top2x[wl] < $Bot2x[wl] then
// Possible Gartley pattern baissier ?
PtxX = $Top2x[wl]
PtyX = High[barindex-PtxX]
PtxA = $Bot2x[wl]
PtyA = Low[barindex-PtxA]
PtxB = $Top3x[wl]
PtyB = High[barindex-PtxB]
PtxC = $Bot3x[wl]
PtyC = Low[barindex-PtxC]
XA = PtyX - PtyA
AB = PtyB - PtyA
BC = PtyB - PtyC
CD = High - PtyC
If (AB >= XA*0.618*(1-marge) and AB <= XA*0.618*(1+marge)) and ((BC >= AB*0.382*(1-marge) and BC <= AB*0.382*(1+marge) and CD >= BC*1.272*(1-marge) and CD <= BC*1.272*(1+marge)) or (BC >= AB*0.886*(1-marge) and BC <= AB*0.886*(1+marge) and CD >= BC*1.618*(1-marge) and CD <= BC*1.618*(1+marge))) and (CD >= XA*0.786*(1-marge) and CD <= XA*0.786*(1+marge)) and PtyX = Highest[PtxB-PtxX+1](High[barindex-PtxB]) and High = Highest[Barindex-PtxB+1](High) then
// 5ème point potentiel trouvé = Barindex
PtxD = Barindex
PtyD = High
drawtriangle(PtxX,PtyX,PtxA,PtyA,PtxB,PtyB) coloured("Red",75) bordercolor("Red",200)
drawtriangle(PtxB,PtyB,PtxC,PtyC,PtxD,PtyD) coloured("Red",150) bordercolor("Red",200)
Endif
Endif
Endif
//Endif
Next
Return
This nice harmonic pattern indicator has been published in the library, just now, find it here with a complete explanation:
Gartley Pattern Indicator (222) for ProRealTime