OPEN-SOURCE SCRIPT

Harmonic Pattern Detector (75 patterns)

Harmonic Pattern Detector offers a record amount of "Harmonic Patterns" in one script, with 75 different patterns detected, together with up to 99 different swing lengths.

🔶 USAGE

תמונת-בזק

Harmonic Patterns are detected from several different ZigZag lines, derived from Swings with different lengths (shorter - longer term)

Depending on the settings 'Minimum/Maximum Swing Length', the user will see more or less patterns from shorter and/or longer-term swing points.

🔹 Fibonacci Ratio

תמונת-בזק

Certain patterns have only one ratio for a specific retrace/extension instead of one upper and one lower limit. In this case, we add a 'Tolerance', which adds a percentage tolerance below/above the ratio, creating two limits.

A higher number may show more patterns but may become less valid.

Hoovering over points B, C, and D will show a tooltip with the concerning limits; adjusted limits will be seen if applicable.

Tooltips in settings will also show which patterns the Fibonacci Ratio applies to.

תמונת-בזק

🔹 Triangle Area Ratio

תמונת-בזק

Using Heron's formula, the triangle area is calculated after the X-Y axis is normalized.

Users can filter patterns based on the ratio of the smallest triangle to the largest triangle.

A lower Triangle Area Ratio number leads to more symmetrical patterns but may appear less frequently.

🔶 DETAILS

תמונת-בזק

Harmonic patterns are based on geometric patterns, where the retracement/extension of a swing point must be located between specific Fibonacci ratios of the previous swing/leg. Different Harmonic Patterns require unique ratios to become valid patterns.

In the above example there is a valid 'Max Butterfly' pattern where:
  • Point B is located between 0.618 - 0.886 retracement level of the X-A leg
  • Point C is located between 0.382 - 0.886 retracement level of the A-B leg
  • Point D is located between 1.272 - 2.618 extension level of the B-C leg
  • Point D is located between 1.272 - 1.618 extension level of the X-A leg


Harmonic Pattern Detector uses ZigZag lines, where swing highs and swing lows alternate. Each ZigZag line is checked for valid Harmonic Patterns. When multiple types of Harmonic Patterns are valid for the same sequence, the pattern will be named after the first one found.

Different swing lengths form different ZigZag lines.

תמונת-בזק

By evaluating different ZigZag lines (up to 99!), shorter—and longer-term patterns can be drawn on the same chart.

🔹 Blocks

תמונת-בזק

The patterns are organized into blocks that can be toggled on or off with a single click.
When a block is enabled, the user can still select which specific patterns within that block are enabled or disabled.

🔹 Visuals

תמונת-בזק

Besides color settings, labels can show pattern names or arrows at point D of the pattern.
Note this will happen 1 bar after validation because one extra bar is needed for confirmation.

An option is included to show only arrows without the patterns.

🔹 Updated Patterns

תמונת-בזק

When a Swing Low is followed by a lower low or a Swing High followed by a higher high, triggering a pattern identical to a previous one except with a different point D, the pattern will be updated. The previous C-D line will be visible as a dashed line to highlight the event. Only the last dashed line is shown when this happens more than once.

תמונת-בזק

🔹 Optimization

The script only verifies the last leg in the initial phase, significantly reducing the time spent on pattern validation. If this leg doesn't align with a potential Harmonic Pattern, the pattern is immediately disregarded. In the subsequent phase, the remaining patterns are quickly scrutinized to ensure the next leg is valid. This efficient process continues, with only valid patterns progressing to the next phase until all sequences have been thoroughly examined.

This process can check up to 99 ZigZag lines for 75 different Harmonic Patterns, showcasing its high capacity and versatility.

🔹 Ratios

The following table shows the different ratios used for each Harmonic Pattern.

'min' and 'max' are used when only one limit is provided instead of 2. This limit is given a percentage tolerance above and below, customizable by the setting 'Tolerance - Fibonacci Ratio'.

For example a ratio of 0.618 with a tolerance of 1% would result in:
  • an upper limit of 0.624
  • a lower limit of 0.612




🔶 SETTINGS

🔹 Swings
  • Minimum Swing Length: Minimum length used for the swing detection.
  • Maximum Swing Length: Maximum length used for the swing detection.


🔹 Patterns
  • Toggle Pattern Block
  • Toggle separate pattern in each Pattern Block


🔹 Tolerance
  • Fibonacci Ratio: Adds a percentage tolerance below/above the ratio when only one ratio applies, creating two limits.
  • Triangle Area Ratio: Filters patterns based on the ratio of the smallest triangle to the largest triangle.


🔹 Display
  • Labels: Display Pattern Names, Arrows or nothing
  • Patterns: Display or not
  • Last Line: Display previous C-D line when updated


🔹 Style
  • Colors: Pattern Lines/Names/Arrows - background color of patterns
  • Text Size: Text Size of Pattern Names/Arrows


🔹 Calculation
  • Calculated Bars: Allows the usage of fewer bars for performance/speed improvement
Chart patternsHarmonic Patternsmultimultitimeframepatterntimeframe

סקריפט קוד פתוח

ברוח TradingView אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יוכלו להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אבל השימוש החוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.

רוצה להשתמש בסקריפ זה בגרף?


PineCoder: pinecoders.com

- We cannot control our emotions,
but we can control our keyboard -

כתב ויתור