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.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.