SELECT LANGUAGE BELOW

Zigzag Pattern Finder – Indicator by dg_factor

Zigzag Pattern Finder - Indicator by dg_factor

Overview

This tool is designed for recognizing patterns dynamically, focusing on how market structures behave. It helps identify custom sequences of pivot points based on zigzag patterns in real time. The goal is to ease the often tedious process of tracking structural changes visually and to lay the groundwork for sequence-based trading, which is part of price action and market structure analysis.

Main Concept

Think of the market as a massive text document. This script acts like a “scanning tool” that helps find the specific sentence you want. For example, if you enter a sequence like “HH, HL, LL, LH,” this indicator will show you exactly where that pattern appears in the text.

Zigzag and Pivot

At its core, this tool uses the ZigZag algorithm, which eliminates market noise by connecting points only when the price reverses beyond a certain threshold. This helps to outline the basic structure of price movements. The highs and lows represented by these lines correspond to high-highs (HH), low-lows (LL), high-lows (HL), and low-highs (LH). These pivot points are crucial in trading theory, particularly in the Dow Theory, as they give a clear indication of whether buyers or sellers are dominating the market.

There are numerous alternatives to ZigZag on TradingView that can yield good results. However, in my view, the open-source model developed by Devrsem offers the best structure to work with. The initial version was based on a percentage deviation. Now, it’s updated to version 6 of Pine Script, featuring minor enhancements to Mintick-based calculations. A special acknowledgment goes to his inspiring contributions.

Mechanics

  • The internal logic of the tool makes use of “chart.point” objects to accurately track price and time coordinates. These objects are copied whenever the orientation shifts to maintain independent references.
  • `f_calc_dev()`: This function calculates the deviation threshold dynamically based on what the user selects—either Mintick or Percent.
  • `f_parse_sequence()`: It takes raw string input, trims unnecessary spaces, and splits it into clear arrays for further processing.
  • `f_check_sequence()`: This function isolates the latest element from the history pivot array and compares it against the user-defined target sequence.
  • The “trade_direction” state machine employs a unique accumulation system rather than a straightforward binary toggle. It increments for consecutive long signals and decrements for consecutive short signals, making the script versatile for developers aiming to create pyramid strategies and dynamic sizing models.

How to Use

  • Load the indicator onto your chart and specify the noise filter parameters like “Depth,” “Deviation Mode,” “Deviation Value,” and “Backstep.”
  • In the settings, enter the desired market structure for trades using comma-separated values (like “HH, HL, LH”).
  • You can define conditions for long entry, long exit, short entry, and short exit separately.
  • Additionally, you can control visual output and set color preferences in the indicator settings.

Alternating Pivot Rules

It’s important to note that because of the ZigZag algorithm’s geometric laws, the market structure must alternate strictly between highs and lows. You cannot have two consecutive highs or two consecutive lows. So, when creating a custom pattern, always follow a high pivot with a low pivot and vice versa.

Some sequences will be invalid, such as “HH, HH” or “LL, LL.” Even if the engine accepts these inputs, these conditions won’t trigger any signals on the chart. Ensuring your custom text sequences maintain this alternating structure is key to receiving valid signals.

Output

The script displays a zigzag line on the chart and notes each confirmed pivot directly. When your target sequence is found, an entry or exit signal will show up on the specified bar. The script continuously provides raw data, including precise “trade_direction” integers and active signal states for tracking. You can also set up automated TradingView alerts based on these signals.

Disclaimer

The default signal sequences are for demonstration only; it’s up to you to define meaningful patterns. This indicator is not a standalone trading strategy or predictive tool. It merely calculates what has already occurred based on strict pivot definitions. It’s crucial to assess the unfolding market structure in real time when the “Last Leg (Repaint)” option is active; this means that if the price moves before the pivot is confirmed, the signal for the current bar could appear and then disappear.

Facebook
Twitter
LinkedIn
Reddit
Telegram
WhatsApp

Related News