What Happens When You Try to Turn a Harmonic Pattern Into Boolean Code

A harmonic pattern takes four seconds to spot by eye. The code that finds the same shape automatically has to make a dozen judgment calls nobody put in the textbook.


A Gartley pattern takes about four seconds to spot on a chart, once you know what you’re looking for. Five points, a familiar zigzag shape, a glance to check the proportions look roughly right, done. Writing code that finds the same pattern automatically has occupied traders and toolmakers for years, and it’s common for two different harmonic scanners, pointed at the exact same chart, to flag different patterns, or the same pattern at different points, or one pattern where the other sees three overlapping candidates. The eye agrees with itself instantly. The code rarely agrees with other code.

The first decision nobody puts in the textbook

A harmonic pattern is defined on five points, X, A, B, C, D, and every one of those points is a swing high or swing low. Before any ratio math can happen, the code first has to decide what counts as a swing point at all, and that’s not a fact sitting in the price data waiting to be read off. It’s a parameter. A pivot high is usually defined as a bar whose high sits above some number of bars on either side of it, and that number is a choice: three bars on each side gives one set of swing points, five bars gives a noticeably different set, because a shallow pullback that qualifies as a swing under a tight definition disappears entirely under a looser one.

Change that single lookback parameter and the whole set of candidate X, A, B, C, D points shifts underneath the pattern search. Two scanners set to different pivot sensitivities aren’t disagreeing about whether a Gartley is present. They’re looking at two different skeletons of the same price history and asking the ratio question against two different sets of points, and neither one is more correct than the other, because the textbook definition of a harmonic pattern was never written with a specific pivot lookback attached to it.

The second decision: how close counts as close enough

Fibonacci ratios in a harmonic pattern are the whole premise. AB should retrace some proportion of XA, CD should extend some proportion of BC, and so on, each leg checked against a small set of accepted ratios. In real price data, those ratios essentially never land exactly. AB retraces 0.601 of XA, not 0.618. Coding the pattern at all requires wrapping every one of those ratios in a tolerance band, some plus-or-minus window around the textbook number, because a rule demanding an exact match would fire on almost nothing, ever.

That tolerance band isn’t a detail, it’s the whole ballgame. Widen it and the scanner starts finding harmonic patterns everywhere, because a wide enough window around several ratios in sequence will eventually catch nearly any five-point zigzag that shows up in noisy price data. Tighten it and the scanner goes quiet for long stretches, technically more faithful to the textbook numbers and correspondingly less useful, since almost nothing in real markets will ever satisfy several tight Fibonacci constraints at once. Every working harmonic scanner has this number set somewhere, usually without much justification for why that particular width got chosen over a slightly wider or narrower one, and the pattern’s apparent hit rate rides almost entirely on that choice.

Finding the pattern is a search, not a check

Put those two decisions together and something becomes clear: detecting a harmonic pattern isn’t a single boolean check the way an RSI crossing 70 is. There’s no one candidate X, A, B, C, D sitting in the data waiting to be verified. At any given moment there are usually several plausible recent swing highs and lows that could serve as X, several that could serve as A once X is picked, and so on down the chain. Finding “the” pattern means searching across that whole space of point combinations for any sequence that happens to satisfy the ratio tolerances end to end.

That’s structurally the same problem as running a combinatorial event miner across a set of boolean columns, just with continuous ratio constraints standing in for discrete events. The search space is smaller and the constraints are tighter, but the shape of the problem, checking many candidate combinations against a threshold and keeping whichever ones clear it, is identical. A harmonic pattern scanner is a specialized combinatorial search wearing a five-letter name and a chart drawing, and it inherits the same vulnerability every combinatorial search has: give it enough candidate combinations to check, and some of them will satisfy the constraints by coincidence rather than by describing anything real about the market.

When more than one valid pattern shows up at once

The tolerance windows create a further problem that rarely gets discussed. Because the ratio checks are ranges rather than exact values, it’s entirely possible for two, three, or more distinct XABCD combinations to simultaneously qualify as valid patterns on overlapping sections of the same chart. The textbook doesn’t say what to do here, because the textbook was written for a person looking at one chart and picking the shape that looks most obviously right. The code has no eye to apply. Whoever wrote it had to insert a tie-breaking rule, most recently completed D point, tightest aggregate ratio fit, first candidate found in the search order, and that rule, invented entirely by the implementer, silently decides which trades the backtest ends up crediting to “the pattern” and which overlapping, equally valid candidate gets discarded without ever showing up in the results.

What the difficulty is actually revealing

None of this means harmonic patterns are fake or that the geometry is meaningless. It means the textbook version was never a rule in the way a moving average crossover is a rule. It was a description of a shape, meant to be recognized by a person exercising judgment about what looks close enough, drawn on a chart where a human’s pattern recognition fills in every gap a computer needs spelled out explicitly. Turning it into code doesn’t make it more objective. It just forces every one of those previously invisible judgment calls, the swing sensitivity, the tolerance width, the tie-break rule, into a parameter someone has to set, and now has to defend, instead of leaving it as an intuition nobody ever had to justify out loud.