Editors' picksOPEN-SOURCE SCRIPT

Auto Chart Patterns [Trendoscope®]

Updated
🎲 Introducing our most comprehensive automatic chart pattern recognition indicator.

Last week, we published an idea on how to algorithmically identify and classify chart patterns.
Algorithmic Identification and Classification of Chart Patterns


This indicator is nothing but the initial implementation of the idea. Whatever we explained in that publication that users can do manually to identify and classify the pattern, this indicator will do it for them.

🎲 Process of identifying the patterns.

The bulk of the logic is implemented as part of the library - chartpatterns. The indicator is a shell that captures the user inputs and makes use of the library to deliver the outcome.

🎯 Here is the list of steps executed to identify the patterns on the chart.
  • Derive multi level recursive zigzag for multiple base zigzag length and depth combinations.
  • For each zigzag and level, check the last 5 pivots or 6 pivots (based on the input setting) for possibility of valid trend line pairs.
  • If there is a valid trend line pair, then there is pattern.


🎯 Rules for identifying the valid trend line pairs
  • There should be at least two trend lines that does not intersect between the starting and ending pivots.
  • The upper trend line should touch all the pivot highs of the last 5 or 6 pivots considered for scanning the patterns
  • The lower trend line should touch all the pivot lows of the last 5 or 6 pivots considered for scanning the patterns.
  • None of the candles from starting pivot to ending pivot should fall outside the trend lines (above upper trend line and below lower trend line)


The existence of a valid trend line pair signifies the existence of pattern. What type of pattern it is, to identify that we need to go through the classification rules.

🎲 Process of classification of the patterns.

We need to gather the following information before we classify the pattern.
  • Direction of upper trend line - rising, falling or flat
  • Direction of lower trend line - rising, falling or flat
  • Characteristics of trend line pair - converging, expanding, parallel


🎯 Broader Classifications
Broader classification would include the following types.

🚩 Classification Based on Geometrical Shapes
This includes
  • Wedges - both trend lines are moving in the same direction. But, the trend lines are either converging or diverging and not parallel to each other.
  • Triangles - trend lines are moving in different directions. Naturally, they are either converging or diverging.
  • Channels - Both trend lines are moving in the same direction, and they are parallel to each other within the limits of error.


🚩 Classification Based on Pattern Direction
This includes
  • Ascending/Rising Patterns - No trend line is moving in the downward direction and at least one trend line is moving upwards
  • Descending/Falling Patterns - No trend line is moving in the upward direction, and at least one trend line is moving downwards.
  • Flat - Both Trend Lines are Flat
  • Bi-Directional - Both trend lines are moving in opposite direction and none of them is flat.


🚩 Classification Based on Formation Dynamics
This includes
  • Converging Patterns - Trend Lines are converging towards each other
  • Diverging Patterns - Trend Lines are diverging from each other
  • Parallel Patterns - Trend Lines are parallel to each others


🎯 Individual Pattern Types
Now we have broader classifications. Let's go through in detail to find out fine-grained classification of each individual patterns.

🚩 Ascending/Uptrend Channel
This pattern belongs to the broader classifications - Ascending Patterns, Parallel Patterns and Channels. The rules for the Ascending/Uptrend Channel pattern are as below
  • Both trend lines are rising
  • Trend lines are parallel to each other

snapshot

🚩 Descending/Downtrend Channel
This pattern belongs to the broader classifications - Descending Patterns, Parallel Patterns and Channels. The rules for the Descending/Downtrend Channel pattern are as below
  • Both trend lines are falling
  • Trend lines are parallel to each other

snapshot

🚩 Ranging Channel
This pattern belongs to the broader classifications - Flat Patterns, Parallel Patterns and Channels. The rules for the Ranging Channel pattern are as below
  • Both trend lines are flat
  • Trend lines are parallel to each other

snapshot

🚩 Rising Wedge - Expanding
This pattern belongs to the broader classifications - Rising Patterns, Diverging Patterns and Wedges. The rules for the Expanding Rising Wedge pattern are as below
  • Both trend lines are rising
  • Trend Lines are diverging.

snapshot

🚩 Rising Wedge - Contracting
This pattern belongs to the broader classifications - Rising Patterns, Converging Patterns and Wedges. The rules for the Contracting Rising Wedge pattern are as below
  • Both trend lines are rising
  • Trend Lines are converging.

snapshot

🚩 Falling Wedge - Expanding
This pattern belongs to the broader classifications - Falling Patterns, Diverging Patterns and Wedges. The rules for the Expanding Falling Wedge pattern are as below
  • Both trend lines are falling
  • Trend Lines are diverging.

snapshot

🚩 Falling Wedge - Contracting
This pattern belongs to the broader classifications - Falling Patterns, Converging Patterns and Wedges. The rules for the Converging Falling Wedge are as below
  • Both trend lines are falling
  • Trend Lines are converging.

snapshot

🚩 Rising/Ascending Triangle - Expanding
This pattern belongs to the broader classifications - Rising Patterns, Diverging Patterns and Triangles. The rules for the Expanding Ascending Triangle pattern are as below
  • The upper trend line is rising
  • The lower trend line is flat
  • Naturally, the trend lines are diverging from each other

snapshot

🚩 Rising/Ascending Triangle - Contracting
This pattern belongs to the broader classifications - Rising Patterns, Converging Patterns and Triangles. The rules for the Contracting Ascending Triangle pattern are as below
  • The upper trend line is flat
  • The lower trend line is rising
  • Naturally, the trend lines are converging.

snapshot

🚩 Falling/Descending Triangle - Expanding
This pattern belongs to the broader classifications - Falling Patterns, Diverging Patterns and Triangles. The rules for the Expanding Descending Triangle pattern are as below
  • The upper trend line is flat
  • The lower trend line is falling
  • Naturally, the trend lines are diverging from each other

snapshot

🚩 Falling/Descending Triangle - Contracting
This pattern belongs to the broader classifications - Falling Patterns, Converging Patterns and Triangles. The rules for the Contracting Descending Triangle pattern are as below
  • The upper trend line is falling
  • The lower trend line is flat
  • Naturally, the trend lines are converging.

snapshot

🚩 Converging Triangle
This pattern belongs to the broader classifications - Bi-Directional Patterns, Converging Patterns and Triangles. The rules for the Converging Triangle pattern are as below
  • The upper trend line is falling
  • The lower trend line is rising
  • Naturally, the trend lines are converging.

snapshot

🚩 Diverging Triangle
This pattern belongs to the broader classifications - Bi-Directional Patterns, Diverging Patterns and Triangles. The rules for the Diverging Triangle pattern are as below
  • The upper trend line is rising
  • The lower trend line is falling
  • Naturally, the trend lines are diverging from each other.

snapshot

🎲 Indicator Settings - Auto Chart Patterns

🎯 Zigzag Settings
Zigzag settings allow users to select the number of zigzag combinations to be used for pattern scanning, and also allows users to set zigzag length and depth combinations.

snapshot

🎯 Scanning Settings
  • Number of Pivots - This can be either 5 or 6. Represents the number of pivots used for identification of patterns.
  • Error Threshold - Error threshold used for initial trend line validation.
  • Flat Threshold - Flat angle threshold is used to identify the slope and direction of trend lines.
  • Last Pivot Direction - Filters patterns based on the last pivot direction. The values can be up, down, both, or custom. When custom is selected, then the individual pattern specific last pivot direction setting is used instead of the generic one.
  • Verify Bar Ratio - Provides option to ignore extreme patterns where the ratios of zigzag lines are not proportionate to each other.
  • Avoid Overlap - When selected, the patterns that overlap with existing patterns will be ignored while scanning. Meaning, if the new pattern starting point falls between the start and end of an existing pattern, it will be ignored.

snapshot

🎯 Group Classification Filters
Allows users to enable disable patterns based on group classifications.

🚩 Geometric Shapes Based Classifications
  • Wedges - Rising Wedge Expanding, Falling Wedge Expanding, Rising Wedge Contracting, Falling Wedge Contracting.
  • Channels - Ascending Channel, Descending Channel, Ranging Channel
  • Triangles - Converging Triangle, Diverging Triangle, Ascending Triangle Expanding, Descending Triangle Expanding, Ascending Triangle Contrcting and Descending Triangle Contracting


🚩 Direction Based Classifications
  • Rising - Rising Wedge Contracting, Rising Wedge Expanding, Ascending Triangle Contracting, Ascending Triangle Expanding and Ascending Channel
  • Falling - Falling Wedge Contracting, Falling Wedge Expanding, Descending Triangle Contracting, Descending Triangle Expanding and Descending Channel
  • Flat/Bi-directional - Ranging Channel, Converging Triangle, Diverging Triangle


🚩 Formation Dynamics Based Classifications
  • Expanding - Rising Wedge Expanding, Falling Wedge Expanding, Ascending Triangle Expanding, Descending Triangle Expanding, Diverging Triangle
  • Contracting - Rising Wedge Contracting, Falling Wedge Contracting, Ascending Triangle Contracting, Descending Triangle Contracting, Converging Triangle
  • Parallel - Ascending Channel, Descending Channgel and Ranging Channel


snapshot

🎯 Individual Pattern Filters
These settings allow users to enable/disable individual patterns and also set last pivot direction filter individually for each pattern. Individual Last Pivot direction filters are only considered if the main "Last Pivot Direction" filter is set to "custom"

snapshot

🎯 Display Settings
These are the settings that determine the indicator display. The details are provided in the tooltips and are self explanatory.
snapshot

🎯 Alerts
A basic alert message is enabled upon detection of new pattern on the chart.
Release Notes
Added option to enable/disable repainting.

When permitted, repainting only updates a pattern if the new coordinates yield a more geometrically accurate representation. While repainting can be beneficial for maintaining precise patterns on the chart, it often carries a negative connotation. Therefore, we've set this option to be off by default, allowing users to choose based on their preferences
Release Notes
Updates

  • Added option to detect patterns based on custom OHLC. This means, users can select external inputs and apply the pattern detection algorithm on oscillators or other indicators provided they have their OHLC values and not a single value.
  • Added option to limit number of patterns on chart.
Release Notes
Library Updates
Release Notes
Minor library updates
Release Notes
Update libraries
Release Notes
Library updates and update to V6
autochartingChart patternsHarmonic PatternshewhomustnotbenamedtrendoscopeZig Zag Indicator

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer