OPEN-SOURCE SCRIPT
ATR ZigZag - Volatility-Filtered Market Structure

Description
This indicator draws ZigZags using an ATR based threshold for direction switching to identify major swing highs and lows. Instead of relying on fractals or fixed bar-count swings, pivots are confirmed only when price moves beyond the prior extreme by:
threshold = ATR(length) × ATR_mult
This filters noise, enforces valid swing structure (high → low → high), and adapts automatically to volatility. The ATR ZigZag is ideal for traders who want a clean, objective view of swing structure without noise. This has many uses, including mapping swing structure, drawing chart patterns, and trading around extremes.
Lag and Repainting
Pivots are confirmed only after price moves sufficiently in the opposite direction. This creates necessary lag. The ZigZag is drawn when this occurs, and will anchor to the high/low in the past. Optional detection dot plots show exactly when confirmation occurred.
What You See
This indicator draws ZigZags using an ATR based threshold for direction switching to identify major swing highs and lows. Instead of relying on fractals or fixed bar-count swings, pivots are confirmed only when price moves beyond the prior extreme by:
threshold = ATR(length) × ATR_mult
This filters noise, enforces valid swing structure (high → low → high), and adapts automatically to volatility. The ATR ZigZag is ideal for traders who want a clean, objective view of swing structure without noise. This has many uses, including mapping swing structure, drawing chart patterns, and trading around extremes.
Lag and Repainting
Pivots are confirmed only after price moves sufficiently in the opposite direction. This creates necessary lag. The ZigZag is drawn when this occurs, and will anchor to the high/low in the past. Optional detection dot plots show exactly when confirmation occurred.
What You See
- ZigZag: dashed gray line, repainted to anchor at the confirmed highs and lows
- Latest Pivot Levels: Dashed horizontal lines at the most recent confirmed high/low.
- Optional Live Swing Leg: A real-time line from the last confirmed pivot to the current swing extreme, updating until a new pivot forms.
- Optional ATR Boxes: 1×ATR shaded zones around the latest pivot for structural context.
- Optional Pivot Confirmation Dots: Markers show the bar where the threshold is crossed and a swing is officially confirmed. This is to understand the lag and see when the ZigZag repainted.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.