Main Page > Articles > Abcd Pattern > The AB=CD Pattern: The Building Block of Harmonic Trading

The AB=CD Pattern: The Building Block of Harmonic Trading

From TradingHabits, the trading encyclopedia · 5 min read · February 28, 2026
The Black Book of Day Trading Strategies
Free Book

The Black Book of Day Trading Strategies

1,000 complete strategies · 31 chapters · Full trade plans

Introduction

The AB=CD pattern, the simplest of all harmonic patterns, is the foundation upon which all other harmonic patterns are built. This pattern, first described by H.M. Gartley, is a four-point structure (A, B, C, and D) that is characterized by its symmetry and specific Fibonacci ratios. The AB=CD pattern is a reversal pattern that can be either bullish or bearish, and it provides a high-probability entry point for traders.

This article will provide a comprehensive analysis of the AB=CD pattern, covering its mathematical definition, the market psychology that underpins its formation, and a practical guide to its implementation in a NinjaScript strategy. We will explore the specific Fibonacci ratios that define the AB=CD pattern, the calculation of its Potential Reversal Zone (PRZ), and the steps to code an AB=CD pattern detector in NinjaScript. The article will also include a detailed data table of the pattern's ratios, the PRZ calculation formula, and a real-world trading example.

The Psychology of the AB=CD Pattern

The AB=CD pattern is a visual representation of the natural rhythm of the market. In a bullish AB=CD pattern, the initial impulse leg (AB) is followed by a retracement to the C point. The subsequent rally to the D point is equal in length to the AB leg, indicating a balanced and symmetrical price movement. The D point represents a point of resistance where sellers are expected to enter the market and push the price lower.

A bearish AB=CD pattern follows the same logic in reverse. The initial downtrend (AB) is followed by a retracement to the C point. The subsequent decline to the D point is equal in length to the AB leg, indicating a balanced and symmetrical price movement. The D point represents a point of support where buyers are expected to enter the market and push the price higher.

Mathematical Definition of the AB=CD Pattern

The AB=CD pattern is defined by a specific set of Fibonacci ratios that create its unique symmetrical structure. The pattern is composed of four points: A, B, C, and D. The D point is the Potential Reversal Zone (PRZ), where the trade is initiated.

PatternC Point Retracement of ABD Point Extension of BC
Bullish AB=CD0.382 - 0.8861.13 - 2.618
Bearish AB=CD0.382 - 0.8861.13 - 2.618

The Potential Reversal Zone (PRZ)

The PRZ of the AB=CD pattern is a confluence of Fibonacci levels that creates a zone of high-probability reversal. The key level in the AB=CD pattern's PRZ is the point where the CD leg is equal in length to the AB leg. The PRZ is further confirmed by the D point, which is a 1.13 to 2.618 extension of the BC leg.

NinjaScript Implementation

Now, let's outline the steps to create an AB=CD pattern scanner in NinjaScript. This scanner will automatically identify potential AB=CD patterns on any chart and timeframe.

Step 1: Employ the ZigZag Indicator

The ZigZag indicator is the foundational tool for identifying the swing points (A, B, C) that form the AB=CD pattern.

Step 2: Define the AB=CD Pattern Logic

Next, we will define the logic for identifying the AB=CD pattern based on its specific Fibonacci ratios. This will involve a series of conditional statements that check if the swing points identified by the ZigZag indicator conform to the AB=CD pattern's rules.

Step 3: Code the NinjaScript Indicator

Now, we can write the NinjaScript code for the AB=CD pattern scanner. The code will use the ZigZag indicator to get the swing points and then apply the AB=CD pattern logic to identify potential patterns. The indicator will then draw the pattern on the chart and alert the trader.

Step 4: Backtest and Optimize

Once the indicator is coded, it is essential to backtest it on historical data to evaluate its performance. The backtesting results will help you to optimize the indicator's parameters, such as the ZigZag deviation and reversal settings, to achieve the best results.

Actionable Example: Trading a Bullish AB=CD

Let's consider a hypothetical scenario on a crude oil futures (CL) 1-hour chart. Our NinjaScript scanner identifies a potential Bullish AB=CD pattern with the following price points:

  • A: 70.00
  • B: 72.00
  • C: 71.00

To validate this pattern, we must check the Fibonacci ratios:

  1. C Point Retracement of AB: The C point must be between a 0.382 and 0.886 retracement of the AB leg.

    • AB leg = 72.00 - 70.00 = 2.00
    • 0.382 retracement = 72.00 - (2.00 * 0.382) = 71.24
    • 0.886 retracement = 72.00 - (2.00 * 0.886) = 70.28
    • Our C point at 71.00 falls within this range.
  2. D Point Calculation (PRZ): The D point is where the CD leg is equal in length to the AB leg.

    • CD leg = AB leg = 2.00
    • D point = 71.00 + 2.00 = 73.00

Therefore, the PRZ for this Bullish AB=CD pattern is at 73.00. A trader would look for signs of a bearish reversal at this level, such as a bearish pin bar or a divergence on the MACD, before entering a short position. A stop-loss order could be placed just above the D point.

Conclusion

The AB=CD pattern is a simple yet effective tool for identifying high-probability trading opportunities. Its symmetrical structure and specific Fibonacci ratios provide a clear and objective framework for identifying these setups. By implementing an AB=CD pattern scanner in NinjaScript, traders can automate the process of identifying these patterns and enhance their trading strategies. As with all trading strategies, risk management is paramount, and the AB=CD pattern should be used in conjunction with other forms of analysis to confirm trading signals. The next articles in this series will continue to explore the rich world of harmonic patterns and their practical application in NinjaScript.