ZigZag ATR Pct

579
ZigZag ATR % Library

A PineScript v6 library for detecting price pivots based on ATR percentage change (volatility shifts) rather than fixed ATR multiples.

How It Works

Traditional ZigZag indicators use a fixed price threshold to detect pivots. This library takes a different approach: pivots are detected when volatility is changing significantly.

The ATR % change measures how much the Average True Range has shifted over a lookback period:
Pine Script®


  • Positive ATR % = Volatility expanding (market becoming more volatile)
  • Negative ATR % = Volatility contracting (market calming down)


Pivots form when |ATR %| exceeds your threshold, capturing turning points during volatility transitions.

Exported Types

  • Settings - Configuration (ATR length, lookback, threshold, display options)
  • Pivot - Pivot point data (price, time, direction, volume, ATR %)
  • ZigZag - Main state container


Exported Functions

  • newInstance(settings) - Create a new ZigZag instance
  • update(zz, atr, atrPct) - Update on each bar
  • getLastPivot(zz) - Get the most recent pivot
  • getPivot(zz, index) - Get pivot at specific index
  • getPivotCount(zz) - Get total number of pivots
  • calcTR() - Calculate True Range
  • calcATR(length) - Calculate ATR using EMA
  • calcATRPct(atr, atrPrev) - Calculate ATR % change
  • calcPricePct(startPrice, endPrice) - Calculate price % change


Usage Example

Pine Script®


Parameters

  1. ATR Length - Period for ATR calculation (default: 14)
  2. ATR Lookback - Bars to look back for ATR % change (default: 14)
  3. ATR % Threshold - Minimum |ATR %| to trigger pivot detection (default: 5.0)
  4. Depth - Minimum bars between pivots (default: 10)


Use Cases

  • Identify reversals during volatility regime changes
  • Filter noise during low-volatility consolidation
  • Detect breakout pivots when volatility expands
  • Build volatility-aware trading systems



This library detects when the market's behavior is changing, not just how much price has moved.

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน