The ZigZag generator draws lines connecting significant swing highs and swing lows, filtering out minor price movements below configurable percentage thresholds. This helps identify the dominant trend direction and major price swings.
Use a Controller object to add the generator to a chart:
const zigZag = controller.addGenerator('ZigZag');
Type: float
Default: 5
Details
The minimum percentage change required to confirm a swing high. A new swing high is registered when price rises by at least this percentage from the previous swing low.
Type: float
Default: 5
Details
The minimum percentage change required to confirm a swing low. A new swing low is registered when price falls by at least this percentage from the previous swing high.
Type: integer
Default: 3
Details
The minimum number of bars between consecutive swing highs or swing lows. This prevents rapid oscillations from generating too many signals.
Type: enum
Default: 'C' (Close)
Values: 'O' (Open) | 'H' (High) | 'L' (Low) | 'C' (Close) | 'hilo' (High/Low)
Details
The price source used for swing detection:
'O', 'H', 'L', 'C': Uses a single OHLC field for both highs and lows.'hilo': Uses the High values for swing highs and Low values for swing lows (most common for candlestick analysis).Type: color
Details
The color of the zigzag line segments moving upward (from a swing low to a swing high).
Type: color
Details
The color of the zigzag line segments moving downward (from a swing high to a swing low).
Type: enum
Default: 'default' (solid)
Values: 'default' | 'dashed' | 'dotted'
Details
The style of the zigzag line.
Type: LineWidth
Default: 2
Details
The width of the zigzag line in pixels.
Type: boolean
Default: false
Details
When enabled, text labels are displayed at each swing point showing the price value.
Type: boolean
Default: false
Details
When enabled, text labels are displayed at each swing point showing the percentage change from the previous swing.
The ZigZag algorithm works as follows:
changeHigh%, a swing high is registered.changeLow%, a swing low is registered.backstep bars separate consecutive swings.The generator draws a continuous path of line segments alternating between upswings and downswings, with each segment colored according to swingHighColor or swingLowColor.
The generator includes a legend entry showing the current changeHigh and changeLow percentage values (e.g., "Up: 5.00 Down: 5.00").