# Harmonic Pattern Detection

Harmonic Pattern Detection is an indicator on [Vela](https://vela.luxalgo.com/chart), our next-generation charting platform, written in Pine Script®.

Anchor five XABCD vertices on the chart and this tool classifies the formation as a Bat, Gartley, Butterfly, or Crab, draws each leg and labels the AB, BC and CD ratios, and projects the Potential Reversal Zone around point D. Alerts fire as price reaches the PRZ. A precision companion for discretionary harmonic traders who want the measuring done for them.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Dec 27, 2021.
- Access: free.
- Concepts: [Harmonic & Fib Ratio Set](https://www.luxalgo.com/library/concept/harmonic-and-fib-ratio-set/) (primary), [Gartley](https://www.luxalgo.com/library/concept/gartley/), [Bat](https://www.luxalgo.com/library/concept/bat/), [Butterfly](https://www.luxalgo.com/library/concept/butterfly/), [Harmonic Patterns](https://www.luxalgo.com/library/concept/harmonic-patterns/)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=cmpwn1xlj002mvhsgyqxxt5ua
- Page: https://www.luxalgo.com/library/indicator/harmonic-pattern-detection/

**Harmonic Pattern Detection** turns manual harmonic work into a guided process: place the X, A, B, C, and D vertices directly on the chart, like a drawing tool, and the indicator classifies the structure as a Bat®, Gartley, Butterfly, or Crab®, labels each leg with its measured ratio, and projects the Potential Reversal Zone (PRZ) around point D. Classification is anchored to the [harmonic ratio set](https://www.luxalgo.com/library/concept/harmonic-and-fib-ratio-set/), so a formation only earns a name when its segments measure within that pattern's ratio ranges. A dashboard confirms which pattern is currently identified, and an alert fires when price reaches the PRZ.

## How to Trade the Harmonic Pattern Detection?

- **Dashboard label prints**: once the vertices frame a valid [Gartley](https://www.luxalgo.com/library/concept/gartley/), Bat, Butterfly, or Crab, the dashboard names it. Bullish patterns argue for longs at the PRZ, bearish for shorts.
- **Price enters the PRZ**: the zone spans point D plus and minus 38.2% of the DX segment; treat it as an area to watch for reversal behavior rather than an exact price.
- **Hover the ratio labels**: each ratio label lists that leg's reference ratios for all four patterns (Bat, Gartley, Butterfly, Crab), useful for judging how cleanly a formation fits.

Vertex placement is the whole game: the five points are adjusted on the chart itself rather than in the settings panel, so refining X, A, B and C (each read at the close of its bar) until the ratios line up is what separates a textbook pattern from a forced one. The D anchor only sets where D is drawn in time; its price is projected from the XA leg at the detected pattern's ratio.

## Harmonic Pattern Detection Settings

- **XA Precision**: the tolerance band around the AB retracement of XA for the Gartley (0.618) and Butterfly (0.786); the Bat, the Crab and every BC and CD check use fixed ranges. With the Gartley's ideal 0.618 XA leg and a precision of 0.01, anything from 0.608 to 0.628 qualifies. Keep it tight: overly wide values let the detection ranges of different patterns overlap, and the defaults are recommended.
- **Bullish** (two color inputs, both titled Bullish in the settings panel): the first colors bullish patterns, the second bearish ones.

## Frequently Asked Questions

### Which patterns can the indicator classify?

Bat, Gartley, Butterfly, and Crab formations, in both bullish and bearish form. The tool works from the vertices you supply, validating and naming what you outline rather than scanning the chart on its own. For rarer geometries beyond these four, [Exotic Harmonics](https://www.luxalgo.com/library/indicator/exotic-harmonics/) extends the same idea.

### How is the Potential Reversal Zone calculated?

The PRZ's limits are referenced from vertex D and offset by 38.2% of the DX segment in each direction. It is a useful general-purpose convention rather than the only valid method, and it can be adapted to the specific pattern detected.

### How do I get access to Harmonic Pattern Detection?

It is free. Add it to your chart from the LuxAlgo Library, with the PRZ alerts built in. You can also copy the source code from this page and run it anywhere Pine Script® runs.

---

Harmonic Trading was created by [Scott M. Carney](https://harmonictrader.com/). Bat®, Crab®, Shark®, AB=CD® and 5-0® are registered trademarks of Scott M. Carney, referenced here under fair use to identify the patterns. LuxAlgo's tools are independent implementations and may differ from his official pattern definitions and software, available at HarmonicTrader.com. LuxAlgo is not affiliated with or endorsed by Scott M. Carney.

## Related indicators

- [Elliott Wave](https://www.luxalgo.com/library/indicator/elliott-wave/) (Elliott & Harmonics): markdown at https://www.luxalgo.com/library/indicator/elliott-wave.md
- [Truncation](https://www.luxalgo.com/library/indicator/truncation/) (Elliott & Harmonics): markdown at https://www.luxalgo.com/library/indicator/truncation.md
- [Cypher](https://www.luxalgo.com/library/indicator/cypher/) (Elliott & Harmonics): markdown at https://www.luxalgo.com/library/indicator/cypher.md
- [5-0](https://www.luxalgo.com/library/indicator/5-0/) (Elliott & Harmonics): markdown at https://www.luxalgo.com/library/indicator/5-0.md
- [ABCD](https://www.luxalgo.com/library/indicator/abcd/) (Elliott & Harmonics): markdown at https://www.luxalgo.com/library/indicator/abcd.md
- [Elliott Hard Rules](https://www.luxalgo.com/library/indicator/elliott-hard-rules/) (Elliott & Harmonics): markdown at https://www.luxalgo.com/library/indicator/elliott-hard-rules.md
- [Three Drive Pattern Detector](https://www.luxalgo.com/library/indicator/three-drive-pattern-detector/) (Elliott & Harmonics): markdown at https://www.luxalgo.com/library/indicator/three-drive-pattern-detector.md
- [Triangle](https://www.luxalgo.com/library/indicator/triangle/) (Elliott & Harmonics): markdown at https://www.luxalgo.com/library/indicator/triangle.md

---

Source: https://www.luxalgo.com/library/indicator/harmonic-pattern-detection/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
