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.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。