N-Pattern Detector (Advanced Logic)Introduction
The N-Pattern Detector (Advanced Logic) is a powerful Pine Script-based tool designed to identify a specific price structure known as the "N-pattern", which often indicates trend continuation or potential breakout points in the market. This pattern combines zigzag pivot logic, retracement filters, volume confirmation, and trend alignment, offering high-probability trading signals.
It is ideal for traders who want to automate pattern detection while applying smart filters to reduce false signals in various markets — including stocks, forex, crypto, and indices.
What is the N-Pattern?
The N-pattern is a 3-leg price formation consisting of points A-B-C-D. It typically follows this structure:
Bullish N-Pattern:
A → Low Pivot
B → Higher High (Impulse)
C → Higher Low (Retracement)
D → Breakout above B (Confirmation)
Bearish N-Pattern:
A → High Pivot
B → Lower Low (Impulse)
C → Lower High (Retracement)
D → Breakdown below B (Confirmation)
The pattern essentially reflects a trend–pullback–breakout structure, making it suitable for continuation trades.
Key Features
1. Intelligent ZigZag Pivot Detection
Uses pivot highs/lows to define key swing points (A, B, C).
Adjustable ZigZag depth to control pattern sensitivity.
Filters noise and avoids false signals in volatile markets.
2. Retracement Validation
Validates the B→C leg as a proper pullback using Fibonacci-based thresholds.
User-defined min and max retracement settings (e.g., 38.2% to 78.6% of A→B leg).
3. Trend Filter via EMA
Filters patterns based on trend direction using a customizable EMA (e.g., 200 EMA).
Only detects bullish patterns above EMA and bearish patterns below EMA (optional).
4. Volume Confirmation
Ensures that impulse legs (A→B, C→D) are supported by stronger volume than the correction leg (B→C).
Adds another layer of confirmation and reliability to detected patterns.
5. Target Projections
Automatically draws 100% A→B projected target from point C.
Optional Fibonacci extensions at 1.272 and 1.618 levels for take-profit planning.
Visually plotted on the chart with colored dashed/dotted lines.
6. Clear Visuals & Labels
Connects all pattern points with colored lines.
Clearly labels points A, B, C, D on the chart.
Uses customizable colors for bullish and bearish patterns.
Includes real-time alerts when a valid pattern is detected.
How to Use It
Add to Chart
Apply the indicator to any chart and time frame. It works across all asset classes.
Adjust Inputs (Optional)
Set ZigZag Depth to control pivot detection sensitivity.
Define Min/Max Retracement levels to match your trading style.
Enable or disable Trend and Volume filters for cleaner signals.
Customize EMA length (default: 200) for trend validation.
Wait for Pattern Confirmation
The indicator constantly scans for valid N-patterns.
A pattern is confirmed only after point D forms (breakout or breakdown).
You’ll see the full pattern drawn with target levels.
Set Alerts
Alerts trigger automatically on confirmation of a bullish or bearish pattern.
You can customize these in TradingView’s alerts panel.