Main Page > Articles > Cypher Pattern > The Cypher Pattern: A Contrarian's Delight

The Cypher Pattern: A Contrarian's Delight

From TradingHabits, the trading encyclopedia · 8 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 Cypher pattern, a relatively new addition to the harmonic trading family, is a unique and effective tool for identifying trading opportunities. This pattern, discovered by Darren Oglesbee, is a five-point structure (X, A, B, C, and D) that is characterized by its distinctive shape and specific Fibonacci ratios. The Cypher pattern is a reversal pattern, but it often appears in trending markets, providing traders with an opportunity to enter a trade in the direction of the overall trend.

This article will provide a comprehensive analysis of the Cypher pattern, covering its mathematical definition, the market psychology that drives its formation, and a practical guide to its implementation in a NinjaScript strategy. We will explore the specific Fibonacci ratios that define the Cypher pattern, the calculation of its Potential Reversal Zone (PRZ), and the steps to code a Cypher 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 Cypher Pattern

The Cypher pattern is a visual representation of a market that is experiencing a retracement within a larger trend. In a bullish Cypher pattern, the initial impulse leg (XA) is followed by a retracement to the B point, which is a shallow retracement. The subsequent rally to the C point extends beyond the A point, indicating that the bulls are still in control. The final leg down to the D point, which is a 0.786 retracement of the XC leg, represents a point of support where buyers are expected to re-enter the market and push the price higher, in line with the overall uptrend.

A bearish Cypher pattern follows the same logic in reverse. The initial downtrend (XA) is followed by a shallow retracement to the B point. The subsequent decline to the C point extends beyond the A point, indicating that the bears are still in control. The final rally to the D point, the 0.786 retracement of the XC leg, represents a point of resistance where sellers are expected to re-enter the market and push the price lower, in line with the overall downtrend.

Mathematical Definition of the Cypher Pattern

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

PatternB Point Retracement of XAC Point Retracement of ABD Point Retracement of XCD Point Extension of BC
Bullish Cypher0.382 - 0.6181.13 - 1.4140.7861.272 - 2.0
Bearish Cypher0.382 - 0.6181.13 - 1.4140.7861.272 - 2.0

The Potential Reversal Zone (PRZ)

The PRZ of the Cypher pattern is a confluence of Fibonacci levels that creates a zone of high-probability reversal. The key level in the Cypher pattern's PRZ is the 0.786 retracement of the XC leg. The PRZ is further confirmed by the BC extension, which typically falls between 1.272 and 2.0.

The formula for calculating the PRZ of a Bullish Cypher is as follows:

PRZ_Level = C - (C - X) * 0.786

For a Bearish Cypher, the formula is:

PRZ_Level = C + (X - C) * 0.786

NinjaScript Implementation

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

Step 1: Employ the ZigZag Indicator

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

Step 2: Define the Cypher Pattern Logic

Next, we will define the logic for identifying the Cypher 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 Cypher pattern's rules.

Step 3: Code the NinjaScript Indicator

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

Here is a simplified code snippet to illustrate the logic:

csharp
// This is a simplified example and not a complete, compilable indicator.

protected override void OnBarUpdate()
{
    // Get the last four swing points from the ZigZag indicator
    double x = ZigZag(Deviation, Reversal)[3].Price;
    double a = ZigZag(Deviation, Reversal)[2].Price;
    double b = ZigZag(Deviation, Reversal)[1].Price;
    double c = ZigZag(Deviation, Reversal)[0].Price;

    // Check for the B point retracement (0.382 - 0.618)
    if (b > a && b < x && (x - b) / (x - a) >= 0.382 && (x - b) / (x - a) <= 0.618)
    {
        // Check for the C point extension (1.13 - 1.414)
        if (c > x && (c - a) / (b - a) >= 1.13 && (c - a) / (b - a) <= 1.414)
        {
            // We have a potential X, A, B, and C point, now look for D
            // ... additional logic to find the D point
        }
    }
}

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 Bearish Cypher

Let's consider a hypothetical scenario on a EUR/JPY 4-hour chart. Our NinjaScript scanner identifies a potential Bearish Cypher pattern with the following price points:

  • X: 130.00
  • A: 128.00
  • B: 129.50
  • C: 131.00

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

  1. B Point Retracement of XA: The B point must be between a 0.382 and 0.618 retracement of the XA leg.
    • XA leg = 130.00 - 128.00 = 2.00
    • 0.382 retracement = 128.00 + (2.00 * 0.382) = 128.76
    • 0.618 retracement = 128.00 + (2.00 * 0.618) = 129.24
    • Our B point at 129.50 falls outside this range. This is not a valid Cypher pattern.

Let's adjust the B point to a valid level, say 129.00.

  • B: 129.00

Now, our B point at 129.00 falls within the 0.382-0.618 retracement zone.

  1. C Point Extension of AB: The C point must be between a 1.13 and 1.414 extension of the AB leg.
    • AB leg = 129.00 - 128.00 = 1.00
    • 1.13 extension = 128.00 - (1.00 * 1.13) = 126.87
    • 1.414 extension = 128.00 - (1.00 * 1.414) = 126.59
    • Our C point at 131.00 is clearly not a valid C point for a bearish Cypher. This highlights the importance of the C point extending beyond the A point in the opposite direction of the XA leg.

Let's re-imagine the pattern with a valid C point.

  • X: 130.00
  • A: 132.00
  • B: 130.77
  • C: 132.50
  1. B Point Retracement of XA: (132.00 - 130.77) / (132.00 - 130.00) = 0.615 (within 0.382-0.618 range)

  2. C Point Extension of XA: (132.50 - 130.00) / (132.00 - 130.00) = 1.25 (within 1.13-1.414 range)

  3. D Point Calculation (PRZ): The D point is the 0.786 retracement of the XC leg.

    • XC Retracement: 132.50 - (132.50 - 130.00) * 0.786 = 130.53*

Therefore, the PRZ for this Bearish Cypher pattern is at 130.53. A trader would look for signs of a bearish reversal at this level, such as a bearish engulfing candle or a divergence on the RSI, before entering a short position. A stop-loss order could be placed just above the C point at 132.50.

Conclusion

The Cypher pattern is a valuable addition to the harmonic trader's toolkit. Its unique structure and specific Fibonacci ratios provide a high-probability setup for entering a trade in the direction of the overall trend. By implementing a Cypher pattern scanner in NinjaScript, traders can automate the process of identifying these patterns and capitalize on these opportunities. As with all trading strategies, risk management and confirmation from other indicators are essential for long-term success. The next articles in this series will continue to explore the diverse world of harmonic patterns and their practical application in NinjaScript.