Williams Fractals

Mark Bill Williams’ fractals in every ticker’s prices: an up fractal is a high above the highs of the two bars before and the two bars after it, a down fractal a low below their lows.

They mark the swing highs and lows of a market; Williams buys a break above the last up fractal and sells a break below the last down fractal.

A fractal needs the bars after it, so it is only known right_bars periods later. It is therefore marked on the bar that confirms it, two periods after the high or low with the defaults, and never on the bar of the high or low itself: the value on a date only uses the prices up to that date, so it can be used in a backtest as it is. The fractal’s price is the High (Low) right_bars periods before the marked date.

The formula is as follows:

\[\text{Up Fractal} \;(t) = 1 \;\text{if High} \;(t - \text{right\_bars}) > \text{every other High from}\; t - \text{left\_bars} - \text{right\_bars} \;\text{to}\; t,\;\; \text{else 0}\] \[\text{Down Fractal} \;(t) = 1 \;\text{if Low} \;(t - \text{right\_bars}) < \text{every other Low from}\; t - \text{left\_bars} - \text{right\_bars} \;\text{to}\; t,\;\; \text{else 0}\]

Also known as: Williams Fractal, fractals, swing high, swing low, FRACTAL.

Example · AAPL, MSFT · 2025

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

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2025-01-01",
    end_date="2025-12-31",
)

fractals = toolkit.technicals.get_williams_fractal(signals_only=True)

fractals["Up Fractal"]

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

On which days in 2025 did Apple or Microsoft confirm an up fractal, using Bill Williams' fractals?

Which returns:

Parameters

get_williams_fractal 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” uses the prices as traded (split-adjusted)."Close"
left_barsintThe bars before the high or low it must exceed. Defaults to 2.2
right_barsintThe bars after the high or low it must exceed, which is also the delay before a fractal is confirmed. Defaults to 2.2
signals_onlyboolWhether to return only the periods in which at least one ticker has a fractal. Defaults to False.False
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 Williams, B.M. (1995). “Trading Chaos: Applying Expert Techniques to Maximize Your Profits.” Wiley.
  • Library Referenced against TA-Lib’s FRACTAL
  • Library Shares similar logic as finta’s WILLIAMS_FRACTAL
Share