PINE LIBRARY
تم تحديثه ZigZag ATR

ZigZag ATR Library
A volatility-adaptive ZigZag indicator that uses Average True Range (ATR) instead of fixed percentage deviation to detect pivot points. This makes the ZigZag dynamically adjust to market conditions — tighter during low volatility, wider during high volatility.
Why ATR instead of Percentage?
The standard ZigZag uses a fixed percentage threshold (e.g., 5%) to determine when price has reversed enough to form a new pivot. This approach has limitations:
ATR-based deviation solves these issues by measuring reversals in terms of actual volatility, not arbitrary percentages.
Key Features
Settings
How to Use
Pine Script®
Exported Types
Exported Functions
Recommended Multiplier Values
Based on TradingView's official ZigZag library, modified to use ATR-based deviation threshold.
A volatility-adaptive ZigZag indicator that uses Average True Range (ATR) instead of fixed percentage deviation to detect pivot points. This makes the ZigZag dynamically adjust to market conditions — tighter during low volatility, wider during high volatility.
Why ATR instead of Percentage?
The standard ZigZag uses a fixed percentage threshold (e.g., 5%) to determine when price has reversed enough to form a new pivot. This approach has limitations:
- A 5% move means very different things for a $10 stock vs a $500 stock
- During high volatility, fixed percentages create too many pivots (noise)
- During low volatility, fixed percentages may miss significant structure
ATR-based deviation solves these issues by measuring reversals in terms of actual volatility, not arbitrary percentages.
Key Features
- Volatility-adaptive pivot detection using ATR × multiplier threshold
- Automatic adjustment to changing market conditions
- Full customization of ATR length and multiplier
- Optional line extension to current price
- Pivot labels showing price, volume, and price change
- Clean library structure for easy integration
Settings
- ATR Length — Period for ATR calculation (default: 14)
- ATR Multiplier — How many ATRs price must move to confirm a new pivot (default: 2.0)
- Depth — Bars required for pivot detection (default: 10)
- Extend to Last Bar — Draw provisional line to current price
- Display options — Toggle price, volume, and change labels
How to Use
Exported Types
- Settings — Configuration for calculation and display
- Pivot — Stores pivot point data, lines, and labels
- ZigZag — Main object maintaining state and pivot history
Exported Functions
- newInstance(settings) — Creates a new ZigZag object
- update(atrValue) — Updates the ZigZag with current ATR (call once per bar)
- lastPivot() — Returns the most recent pivot point
Recommended Multiplier Values
1.0 - 1.5 → More sensitive, more pivots, better for scalping
2.0 - 2.5 → Balanced, good for swing trading (default)
3.0+ → Less sensitive, major pivots only, better for position trading
Based on TradingView's official ZigZag library, modified to use ATR-based deviation threshold.
ملاحظات الأخبار
v2Update v2: Added xATR Display Mode
What's New
Added a new display mode for the Reversal Price Change label: ATR multiples.
You can now see each swing's magnitude expressed as a multiple of ATR (e.g., "+2.35x ATR"), giving you instant insight into the significance of each move relative to current volatility.
New Display Modes
The differencePriceMode setting now accepts three options:
- Absolute — Raw price difference (e.g., "+$5.25")
- Percent — Percentage change (e.g., "+2.5%")
- ATR — ATR multiples (e.g., "+2.35x ATR") ← NEW
Why xATR?
- A 3x ATR move is significant regardless of absolute price or percentage
- Instantly compare swing magnitudes across different volatility regimes
- Better context for position sizing and stop placement
- Natural complement to ATR-based pivot detection
Usage Example
Default Changed
The default differencePriceMode is now "ATR" instead of "Absolute" to better align with the ATR-based nature of this library.
Backward compatible — existing code using "Absolute" or "Percent" modes continues to work unchanged.
مكتبة باين
كمثال للقيم التي تتبناها TradingView، نشر المؤلف شيفرة باين كمكتبة مفتوحة المصدر بحيث يمكن لمبرمجي باين الآخرين من مجتمعنا استخدامه بحرية. تحياتنا للمؤلف! يمكنك استخدام هذه المكتبة بشكل خاص أو في منشورات أخرى مفتوحة المصدر، ولكن إعادة استخدام هذا الرمز في المنشورات تخضع لقواعد الموقع.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
مكتبة باين
كمثال للقيم التي تتبناها TradingView، نشر المؤلف شيفرة باين كمكتبة مفتوحة المصدر بحيث يمكن لمبرمجي باين الآخرين من مجتمعنا استخدامه بحرية. تحياتنا للمؤلف! يمكنك استخدام هذه المكتبة بشكل خاص أو في منشورات أخرى مفتوحة المصدر، ولكن إعادة استخدام هذا الرمز في المنشورات تخضع لقواعد الموقع.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.