AB=CD Patterns

Script that detects "AB=CD" patterns on the chart. Unlike other scripts, it doesn't put a bunch of unnecessary lines and mysterious arrows on the chart. It clearly indicates where a pattern can be identified and labels it with either a "buy" or "sell" label to show if it's a bearish or bullish pattern .

  • You can check an unlimited number of the high/low points. Use the "Number of points to check" option to configure how many points to check. Remember that checking for too many points in the past will make this script slower (or it can even timeout and cause a 'Script Error').
  • You can configure the error margin using the "Error tolerance (in %)" configuration option. It defines how much the detected AB=CD pattern can differ from the "ideal" pattern. With a 5% error tolerance, if the "ideal" retracement is equal to 0.618, we accept a retracement between 0.5871 and 0.6489.
  • You can change how many previous candles are considered when checking for the high/low points by changing the "Depth of a ZigZag pattern" option. If you choose a high number, there will be fewer points to check, and the script will be faster. If you choose a low number, the script will be slower, but it will check more points. To see the high/low points on the chart, enable the "Draw ZigZag" option.
  • You can change the lines' width using the "ZigZag line width" and "Formation line width". It's a purely cosmetic option, and it doesn't change how the script works.

It's currently using the 0.382 to 0.886 retracement levels for the ABC leg and 1.13 to 2. 618 retracement levels for the BCD leg. In the future, there will be a configuration option to use the "ideal" ratio proposed by Scott Carney (more strict than the current one).

Release Notes: Version 1.1

The first update adds the "Strict" ratio option for those of you who want to use a more strict variant for the retracement levels.

  • Added option to select between "Strict" or "Standard" ratios. "Standard" means that we check 0.382, 0.5, 0.618, 0.786 and 0.886 retracement levels for point C (in the ABC leg) and 1.13, 1.272, 1.414, 1.618, 2.0, 2.24 and 2.618 for point D (in the BCD leg). "Strict" means that only check 0.618 and 0.786 for point C and 1.272 and 1.618 for point D.
  • Added "Move charts" option. When you have many formations on the chart, and they share the same points, only the topmost line is visible. With the "Move Charts" option enabled (it's disabled by default), we move all those points up/down a bit to make all the lines nicely visible and easy to follow.
Release Notes: Version 1.2 Alerts, more configuration options and stability improvements

  • Alerts - you can now add alerts to get a notification when a new AB=CD pattern appears.
  • Configurable "Move charts" option - you can select by how many percent you want to move charts that are hiding each other. This is useful when you use a small interval where moving charts by 1% of a total price will move them too much.
  • Indicator is much more stable for smaller intervals. Before, when you used a short interval (seconds or minutes), the script crashed almost immediately after the first few bars. Now it should work much better. However, it might still crash from time to time - that's when it's referencing points from the past that TradingView discards when new bars are added to the chart. If this happens, refresh the page or hide and show the indicator again (also, decrease the "Number of points to check" for better performance). If you are using 1H or a larger interval, you probably won't see this problem at all.
Protected script
This script is published closed-source and you may use it freely. You can favorite it to use it on a chart. You cannot view or modify its source code.
Want to use this script on a chart?
You can find more information about our scripts at


Thanks for this helpful script :)
+1 Reply
Is there a way to add an alert everytime the pattern shows?
@Ghosto, Not yet. I'm trying to figure out a good way to do this. The problem is - because there is some error margin, whenever the pattern appears, it will usually appear for the next few bars (let's say there was a high bar, but the next one is slightly higher, and the next one is higher too, etc.). This will trigger multiple alerts for the same pattern. So I'm still looking for a good solution to that (apart from manually disabling and enabling the alert, which is doable, but annoying).
@Ghosto, alerts are now available.
Is it possible for me to have access to the chart script/ source code?
@Ghosto, Hi, I'm afraid that's not possible. This script shares a lot of code with some other invite-only scripts, so it can't be open-sourced.
Home Stock Screener Forex Screener Crypto Screener Economic Calendar About Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter