Zig Zag

Calculate the Zig Zag: the swing highs and lows of the prices, ignoring moves smaller than a threshold, which shows the trend’s turning points.

The Zig Zag filters out moves smaller than the sensitivity. It follows the highest high of a rising leg until the low falls the sensitivity below it, which confirms that high as a swing high and starts a falling leg from that low, and the lowest low of a falling leg until the high rises the sensitivity above it. Drawn on a chart, the lines between the confirmed swing highs and lows are the zig zag, which shows the waves of the market without the noise in between.

The formula is as follows:

\[\text{In a rising leg:}\;\; \text{the trend turns down when Low}(t) \leq \text{Extreme} \cdot (1 - \text{Sensitivity}),\;\; \text{otherwise}\;\; \text{Extreme} = \operatorname{High}(t) \;\text{when High}(t) \geq \text{Extreme}\] \[\text{In a falling leg:}\;\; \text{the trend turns up when High}(t) \geq \text{Extreme} \cdot (1 + \text{Sensitivity}),\;\; \text{otherwise}\;\; \text{Extreme} = \operatorname{Low}(t) \;\text{when Low}(t) \leq \text{Extreme}\]
  • A leg only turns once at least Minimum Trend Length periods have passed since its extreme

Also known as: ZIGZAG, Zig Zag, swing filter, filtered waves.

Example · SIUSD · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_zigzag:

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["SIUSD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_zigzag(sensitivity=0.1).xs("SIUSD", level=1, axis="columns")

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

Where were the turning points of silver's price in 2025, using a Zig Zag with a 10% sensitivity?

Which returns:

Parameters

get_zigzag accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Options are: “intraday” (intraday prices), “daily” (daily prices), “weekly” (weekly prices), “monthly” (monthly prices), “quarterly” (quarterly prices), “yearly” (yearly prices). Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”, in which case the high and low prices are adjusted for dividends in the same way."Close"
sensitivityfloatThe reversal from the extreme that turns a leg, as a decimal (0.05 is 5%). Defaults to 0.05.0.1
minimum_trend_lengthintThe number of periods since the extreme of a leg before it can turn. Defaults to 1.1
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the values. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Merrill, A.A. (1977). “Filtered Waves: Basic Theory.” Analysis Press.
  • Library Referenced against TA-Lib’s ZIGZAG
Share