New! WiseTrader Toolbox for Amibroker is now available with:
  • Advanced Adaptive Indicators
  • Advanced Pattern Exploration
  • Neural Networks
  • And Much More...
GoTo WiseTrader Toolbox


Contribute an indicator to the library by clicking here. Note you must be logged in.


Popular Indicators


5 / 5 (Votes 4)


Automatic Detection of Harmonic Patterns – Gartley, Bat, Butterfly and Crab.

Zig Zag is not used in this AFL. It is based on fractals

Contact –

Modernized by E.M.Pottasch (Dec 2016).
- All calculations by the original author left as they were.
- Improved visualisation of the patterns.

The code I used is the original code from:
file: (2009)

Here is a screenshot of how the indicator looks:

Similar Formulas



you have make them beautiful only, am I true? (I don’t want to repeat testing)

could you please add approximated reversals of these pattern in the chart (please)?

@gmail dot com

you can add for instance

PlotShapes( shapeDigit4*BearHar4, colorRed, O, L, -10 );
PlotShapes( shapeSmallCircle*BearHar, colorOrange, O, H, 10 );

for the bearisch patterns. Then shapeDigit4 is put at the point where the harmonic pattern with 4 pivots is known. Then it looks for the 5-th point. I only start plotting the harmonic patterns when the complete pattern is know at the earliest point. The point is shown by the orange colored shapeSmallCircle*BearHar.

Same for the bullish patterns you can add:

PlotShapes( shapeDigit4*BullHar4, colorBlue, O, H, 10 );
PlotShapes( shapeSmallCircle*BullHar, ColorLightBlue, O, L, -10 );

This is how it is written by the original author.

So if you add:

PlotShapes( shapeDigit4*BullHar4, colorBlue, O, H, 10 );
PlotShapes( shapeSmallCircle*BullHar, ColorLightBlue, O, L, -10 );
PlotShapes( shapeDigit4*BearHar4, colorRed, O, L, -10 );
PlotShapes( shapeSmallCircle*BearHar, colorOrange, O, H, 10 );

on the bottom of the code the orange and lightblue dots show when the patterns started and what its path has been during its forming.

Also try to use the Playback in Amibroker to see how they develop.

I made a little update, see:

now if you go to the parameter window and toggle ON:

“Show Points of Pattern Development”

then you will see the points appear in the chart where your harmonic patterns starts to develop. Note that in some cases the 4-point figure developed but it will not result in a harmonic pattern because the 5-th points is not developed. However, the 4-th point shapeDigit4 is still plotted in the chart.

Mr pottash can you add 123 pattern in it and also exploration function then I’ll be very grateful to you. Waiting for your reply

hi, thanks for your comment. Maybe in a later version because I have to study the topic a bit myself. I wanted to add the ABCD pattern first since it is often part of the current patterns. However, I am still not sure what Swing Max/Min parameters to use. The original author uses certain numbers but I am not sure where he got them from.

If anyone uses these patterns for their trading successfully and knows which Swing parameters to use please email me (

for now I have an update of the code here:

you can now just plot 1 pattern, e.g. bullish gartley without getting the chart poluted with other stuff.

Also have a look at the parameter window. You can now also show X,A,B,C,D labels. Also you can show socalled “points of pattern development”. If you turn this on and do a playback you will see what they are.

Mr. Pottash ratio given by you fine, actually harmonic pattern is not for intraday trade. Actually around 80% of the harmonic pattern work correctly in day chart if you apply it with fibonacci. I am using harmonic with your vstop vwap formula because in your vwap formula fibonacci is very nice.
In case of ratio you can take some help from harmonic pattern books, I can mail you just drop a message in my inbox
Waiting for your reply

Another important point is that Mr pottash please keep more than one pattern in a chart because if you keep one pattern then problem is that when a pattern completed with last 20 bar and another pattern is making with last 40 bar then last pattern will not be visible


thanks for your comment. I will email later. With respect to exploration, that is simple to add, will show later how.

There was a small problem that some patterns are drawn while they should not and some “patternDevelopmentPoints” are drawn after the fact. This is because the pattern can only be known at rightStrength bars after point 4. The original code does not take this into account. The corrected code is here:

this should be correct now, although these fractal pivots on a rare occasion still give a problem. I used the “fractal cleaning” code by the original author since my own code has issues as well.

I also made a version with ATR pivots. I might post this later because I need to still check this

again I found some problems with the original code that emerge on occasion.

corrected for that:

hope I found all the problems now

latest code with respect to this, using fractal pivots, find it here:

Please login here to leave a comment.

Main Menu