OPEN-SOURCE SCRIPT
Price Action ZigZag (Impulses & Corrections)

This indicator tracks price structure by connecting significant swing highs and lows—giving a clear, actionable “ZigZag” view of market movement. It automatically maps the underlying price action as alternating impulses (trend legs) and corrections (pullbacks), directly on your chart, for any timeframe.
How does it work?
Swing Detection:
The script uses the user-selected “pivot length” to identify confirmed swing highs and lows with Pine Script’s ta.pivothigh and ta.pivotlow.
These pivots only print after full confirmation, making all lines strictly non-repainting.
ZigZag Drawing:
Impulse vs Correction Logic:
Labels & Colors:
Key Features:
How to use:
Disclaimer:
This script is a visualization and analysis tool for educational purposes—it does not predict future price movement, guarantee results, or provide trading signals. Always use sound risk management and your own judgment in live trading.
How does it work?
Swing Detection:
The script uses the user-selected “pivot length” to identify confirmed swing highs and lows with Pine Script’s ta.pivothigh and ta.pivotlow.
These pivots only print after full confirmation, making all lines strictly non-repainting.
ZigZag Drawing:
- After pivots are captured, the indicator connects each alternating swing with lines that trace the progression of price structure.
- Each line segment is mapped according to the sequence and direction of swings:
- Impulse: Moves that break further away from prior swing in the same direction (continuations/uptrends/downtrends)
- Correction: Moves that pull price back, but do not extend past the previous impulse (retracements/sideways action)
Impulse vs Correction Logic:
- Bullish impulse: swing from a higher low to a higher high (fast upward moves after a low)
- Bearish impulse: swing from a lower high to a lower low (fast downward moves after a high)
- Corrections appear as smaller lines between alternating swing points not leading to new trend extension.
Labels & Colors:
- Impulse lines are drawn teal (customizable), corrections in gray.
- Tiny labels ("Impulse", "Correction") are shown for clarity (optional).
- Most recent pivots are highlighted with yellow dots for quick visual reference.
Key Features:
- User-adjustable pivot length controls sensitivity and structure size (scalp to swing).
- Distinguishes between impulses and corrections instantly on the chart.
- Labels and color coding for clarity—traders can spot trend continuation vs. pullback at a glance.
- Non-repainting confirmed pivots and lines; never show incomplete data.
- Fully customizable appearance—all colors and label display adjustable in settings.
- Zero lookahead or repainting: all signals use confirmed, historical price only.
How to use:
- Add to any chart and set 'Swing Length' to fit your trading style (shorter for scalping, longer for bigger structure).
- Follow the ZigZag lines to see when price makes an impulse vs. correction, and use this to identify high-probability momentum or reversal zones.
- Combine this script with your own analysis/strategy or other indicators for deeper context.
- Adjust colors and label options for your preferred chart clarity.
Disclaimer:
This script is a visualization and analysis tool for educational purposes—it does not predict future price movement, guarantee results, or provide trading signals. Always use sound risk management and your own judgment in live trading.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.