OPEN-SOURCE SCRIPT
Aktualisiert ABCD Pattern Finder

**Detailed Indicator Description**
Your indicator is an **ABCD Pattern Finder** for TradingView. It scans price action for swing-based **AB=CD harmonic-style patterns**, confirms whether the pattern meets your rules, then plots the pattern and related trade levels directly on the chart.
**Core Purpose**
The indicator is designed to find situations where price makes:
**A to B:** an initial impulse move.
**B to C:** a retracement or pullback.
**C to D:** a second move that is approximately equal to the A-to-B move.
When the C-to-D leg completes and passes the filter rules, the indicator treats point **D** as the trade-confirmation area. It then displays an entry reference, stop loss, and three take-profit levels.
**Bullish and Bearish Logic**
A **bullish setup** is one where the completed pattern suggests a potential long trade after point D.
A **bearish setup** is one where the completed pattern suggests a potential short trade after point D.
The indicator uses the sequence of highs and lows to decide whether the pattern is bullish or bearish. It does not simply mark every four-point swing; the swing sequence must form a valid ABCD structure.
**Zigzag Inputs**
**Pivot Bars Left** controls how many bars to the left must be considered when confirming a swing high or swing low.
**Pivot Bars Right** controls how many bars to the right must pass before a pivot is confirmed.
Higher values make the indicator less sensitive and produce fewer patterns. Lower values make it more sensitive and produce more patterns, but with more noise.
**Pattern Quality Inputs**
**Min CD/AB Time Ratio** sets the minimum amount of time the CD leg must take compared with the AB leg. This prevents CD from forming too quickly.
**Max CD/AB Time Ratio** sets the maximum amount of time CD can take compared with AB. This prevents slow, dragged-out CD legs from qualifying.
**AB=CD Equality Tolerance** controls how close the CD leg must be to the AB leg in price size. A value of **0.10** means CD can be within plus or minus 10% of AB.
**Min BC Retracement of AB** sets the shallowest acceptable pullback from B to C.
**Max BC Retracement of AB** sets the deepest acceptable pullback from B to C.
**Min AB Size ATR Multiple** requires the AB leg to be large enough compared with ATR. This helps filter out small, low-quality patterns.
**ATR Length** controls the ATR calculation used for volatility-based filtering and stop placement.
**Disallow Pattern Overlap** prevents a new pattern from being confirmed inside the range of an already confirmed pattern.
**Trade Inputs**
**Stop ATR Buffer Beyond D** places the stop loss beyond point D by a volatility-based buffer. A larger value gives the trade more room, while a smaller value creates a tighter stop.
**TP1 Fibonacci Level** sets the first profit target based on the A-to-D range.
**TP2 Fibonacci Level** sets the second profit target.
**TP3 Fibonacci Level** sets the third profit target.
The default target structure is TP1 at **0.618**, TP2 at **1.0**, and TP3 at **1.382** of the A-to-D range.
**Display Inputs**
**Trade Display Bars Forward** controls how far the entry, stop, and target lines extend to the right of the current candle.
**Show Trade Levels** turns entry, stop loss, and target lines on or off.
**Show ABCD Lines** turns the A-B, B-C, and C-D pattern lines on or off.
**Show ABCD Labels** turns the A, B, C, and D labels on or off.
You can also customize colors for the confirmed pattern, entry line, stop line, and target lines.
**Historical Pattern Inputs**
**Show Historical AB=CD Patterns** controls whether older confirmed patterns remain visible.
**Historical Closed Lookback** controls how many recently closed patterns are included in the historical visual/stat window.
**Closed Trade Lookback** lets you visually rewind and highlight a previous closed trade. A value of **0** shows the most recent trade. A value of **1** shows the trade before that.
**Closed Trade Lookback Color** controls the color used when reviewing an older closed trade.
**Confirmation Triangles**
The indicator can plot a triangle when a pattern is confirmed.
A bullish confirmation uses the bullish triangle color.
A bearish confirmation uses the bearish triangle color.
You can turn these triangles on or off and choose their size: **Tiny, Small, Normal, or Large**.
**AD Line Inputs**
The indicator can draw a line from point **A** to point **D**, extended to the right.
You can control whether this line appears, plus its color, width, and style: **Solid, Dashed, or Dotted**.
**Stats Window**
The stats window displays historical performance for TP1, TP2, and TP3.
For each target, it shows:
**Wins:** how many closed trades reached that target.
**Closed:** how many closed trades were evaluated.
**Rate:** the win rate for that target.
The stats are recalculated using your current trade input settings, so changing stop or target values updates the displayed historical results.
**Alerts**
The indicator includes two alerts:
**New ABCD Pattern Detected** triggers when a valid pattern is found.
**ABCD Pattern Entry at D** triggers when the pattern confirmation/entry condition occurs at point D.
Your indicator is an **ABCD Pattern Finder** for TradingView. It scans price action for swing-based **AB=CD harmonic-style patterns**, confirms whether the pattern meets your rules, then plots the pattern and related trade levels directly on the chart.
**Core Purpose**
The indicator is designed to find situations where price makes:
**A to B:** an initial impulse move.
**B to C:** a retracement or pullback.
**C to D:** a second move that is approximately equal to the A-to-B move.
When the C-to-D leg completes and passes the filter rules, the indicator treats point **D** as the trade-confirmation area. It then displays an entry reference, stop loss, and three take-profit levels.
**Bullish and Bearish Logic**
A **bullish setup** is one where the completed pattern suggests a potential long trade after point D.
A **bearish setup** is one where the completed pattern suggests a potential short trade after point D.
The indicator uses the sequence of highs and lows to decide whether the pattern is bullish or bearish. It does not simply mark every four-point swing; the swing sequence must form a valid ABCD structure.
**Zigzag Inputs**
**Pivot Bars Left** controls how many bars to the left must be considered when confirming a swing high or swing low.
**Pivot Bars Right** controls how many bars to the right must pass before a pivot is confirmed.
Higher values make the indicator less sensitive and produce fewer patterns. Lower values make it more sensitive and produce more patterns, but with more noise.
**Pattern Quality Inputs**
**Min CD/AB Time Ratio** sets the minimum amount of time the CD leg must take compared with the AB leg. This prevents CD from forming too quickly.
**Max CD/AB Time Ratio** sets the maximum amount of time CD can take compared with AB. This prevents slow, dragged-out CD legs from qualifying.
**AB=CD Equality Tolerance** controls how close the CD leg must be to the AB leg in price size. A value of **0.10** means CD can be within plus or minus 10% of AB.
**Min BC Retracement of AB** sets the shallowest acceptable pullback from B to C.
**Max BC Retracement of AB** sets the deepest acceptable pullback from B to C.
**Min AB Size ATR Multiple** requires the AB leg to be large enough compared with ATR. This helps filter out small, low-quality patterns.
**ATR Length** controls the ATR calculation used for volatility-based filtering and stop placement.
**Disallow Pattern Overlap** prevents a new pattern from being confirmed inside the range of an already confirmed pattern.
**Trade Inputs**
**Stop ATR Buffer Beyond D** places the stop loss beyond point D by a volatility-based buffer. A larger value gives the trade more room, while a smaller value creates a tighter stop.
**TP1 Fibonacci Level** sets the first profit target based on the A-to-D range.
**TP2 Fibonacci Level** sets the second profit target.
**TP3 Fibonacci Level** sets the third profit target.
The default target structure is TP1 at **0.618**, TP2 at **1.0**, and TP3 at **1.382** of the A-to-D range.
**Display Inputs**
**Trade Display Bars Forward** controls how far the entry, stop, and target lines extend to the right of the current candle.
**Show Trade Levels** turns entry, stop loss, and target lines on or off.
**Show ABCD Lines** turns the A-B, B-C, and C-D pattern lines on or off.
**Show ABCD Labels** turns the A, B, C, and D labels on or off.
You can also customize colors for the confirmed pattern, entry line, stop line, and target lines.
**Historical Pattern Inputs**
**Show Historical AB=CD Patterns** controls whether older confirmed patterns remain visible.
**Historical Closed Lookback** controls how many recently closed patterns are included in the historical visual/stat window.
**Closed Trade Lookback** lets you visually rewind and highlight a previous closed trade. A value of **0** shows the most recent trade. A value of **1** shows the trade before that.
**Closed Trade Lookback Color** controls the color used when reviewing an older closed trade.
**Confirmation Triangles**
The indicator can plot a triangle when a pattern is confirmed.
A bullish confirmation uses the bullish triangle color.
A bearish confirmation uses the bearish triangle color.
You can turn these triangles on or off and choose their size: **Tiny, Small, Normal, or Large**.
**AD Line Inputs**
The indicator can draw a line from point **A** to point **D**, extended to the right.
You can control whether this line appears, plus its color, width, and style: **Solid, Dashed, or Dotted**.
**Stats Window**
The stats window displays historical performance for TP1, TP2, and TP3.
For each target, it shows:
**Wins:** how many closed trades reached that target.
**Closed:** how many closed trades were evaluated.
**Rate:** the win rate for that target.
The stats are recalculated using your current trade input settings, so changing stop or target values updates the displayed historical results.
**Alerts**
The indicator includes two alerts:
**New ABCD Pattern Detected** triggers when a valid pattern is found.
**ABCD Pattern Entry at D** triggers when the pattern confirmation/entry condition occurs at point D.
Versionshinweise
**Fix Description**The issue was that the indicator entered the trade at the **confirmation candle close**, but the stats engine was also using that same candle’s high/low to test for stop-loss and take-profit hits.
That was logically wrong because the trade does not exist until the candle closes.
**What I Changed**
I updated the stats engine so the confirmation candle is used only to **create the trade**, not to judge the trade outcome.
Now the sequence is:
1. ABCD pattern confirms.
2. Entry is recorded at the current close.
3. Trade is stored as active.
4. The confirmation candle is skipped for SL/TP testing.
5. SL/TP evaluation starts on the next confirmed candle.
**Why This Matters**
Before the fix, a candle could create false results.
Example:
* Pattern confirms at candle close.
* Earlier in that same candle, price already touched TP1 or SL.
* The old stats engine could count that as a valid hit.
* But the trade was not active yet, so that hit should not count.
The updated version prevents that.
**What Stayed The Same**
The replay-based stats logic still works the same way:
* It stores raw pattern data.
* It stores the post-entry high/low path.
* It recalculates outcomes using your current SL and TP input settings.
* Changing `Stop ATR Buffer`, `TP1`, `TP2`, or `TP3` still updates the stats properly.
**Bottom Line**
The fix makes the stats cleaner and more realistic because results now begin **after entry**, not before entry.
Versionshinweise
**ABCD Pattern Indicator — Change Log**---
**What This Indicator Does**
This is an ABCD harmonic pattern detection tool. It finds valid four-point ABCD structures on your chart, draws them, manages trade levels from the D pivot, tracks historical outcomes through a replay-based stats system, and fires alerts when a pattern is detected. The D pivot forming and passing all structural filters is what triggers the trade — there is no secondary confirmation step required.
---
**Update 1 — Search Depth**
A new Search Depth input was added to the Zigzag settings group, sitting alongside the existing Pivot Bars Left and Pivot Bars Right inputs. This keeps all three bar-related settings together in one place since they all relate to how the indicator scans the chart.
- The default value is 2000 bars, meaning the indicator will look back up to 2000 bars from the current bar when deciding whether a pattern's A pivot is recent enough to be considered valid
- The minimum is 100 bars and the maximum is 5000 bars, adjustable in steps of 100
- A tooltip explains what the setting does — it controls how many bars back the indicator scans for ABCD patterns
The underlying indicator declaration was also updated to include `max_bars_back = 2000` so that Pine Script actually loads enough historical price data to support a 2000 bar search. Without this, Pine might not calculate far enough back even if the Search Depth input is set to a high number.
**How Search Depth Works In Practice**
When a new potential ABCD pattern is detected, the indicator checks whether the A pivot falls within the search depth window. If the A pivot formed more bars ago than the Search Depth setting allows, the pattern is ignored and not drawn.
- Lowering the Search Depth focuses the indicator on more recent patterns only, which can reduce clutter on the chart
- Raising it allows older pattern structures to be detected and drawn
- Setting it to its maximum of 5000 gives the broadest possible historical coverage
- Search Depth works independently of the Historical Closed Lookback — Search Depth controls what patterns get detected in the first place, while Historical Closed Lookback controls how many confirmed patterns stay visible on the chart after detection
---
**Update 2 — Settings Group Reorganization**
The Historical Patterns settings group was moved from its previous location — where it sat between the Display group and the confirmed pattern color settings — to a new position directly below the Zigzag group.
The reasoning is straightforward. The Zigzag group contains Pivot Bars Left, Pivot Bars Right, and Search Depth, all of which control how broadly the indicator scans for patterns. Historical Patterns controls how many of those found patterns stay visible on the chart and how the lookback rewind feature behaves. These two groups are closely related in purpose — both deal with scope and range of what you see — so having them sit together at the top of the settings panel makes the workflow more intuitive.
The settings panel order is now:
- **Zigzag** — pivot bar settings and search depth
- **Historical Patterns** — lookback count, colors, and trade rewind
- **Pattern** — all structural and filter rules for what counts as a valid ABCD
- **Trade** — stop loss and take profit settings
- **Display** — visual toggles and colors for lines, labels, and triangles
- **AD Line** — the line drawn from pivot A to pivot D
- **Stats Window** — position, size, and color settings for the stats box
---
**What Was Not Changed**
The pattern detection filters, the BC retracement rules, the AB equality tolerance, the time symmetry checks, the ATR size filter, the trade levels, the stop and take profit logic, the replay-based stats window, the trade lookback rewind feature, the AD line, confirmation triangles, and all alert conditions are all exactly as they were in the original version.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.