Bill Williams indicator guide
Williams Fractals: five-bar rules and confirmation
A Williams fractal identifies a local high or low using a center candle and two candles on each side. The five-bar pattern becomes knowable only after its right side forms. In the closing-bar example below, a fractal centered on bar 3 is confirmed at bar 5 close, even if its triangle is drawn back on bar 3.
Pattern location
Bar 3: the center high or low
Signal availability in this example
Bar 5 close: two bars later
The strict five-bar rule
For an up fractal, the center high exceeds each of the other four highs. For a down fractal, the center low is below each of the other four lows. Candle color and the direction of the close do not enter these comparisons. The surrounding highs or lows do not need to rise or fall in a staircase.
Up: H3 > H1, H2, H4, H5
Down: L3 < L1, L2, L4, L5
This page uses strict inequalities. Equal values reject the candidate. That choice makes the example reproducible; it is not a claim that every platform or community script uses the same rule for flat tops and bottoms. A wider window or a plateau rule defines a different detector.
Definition sources: TradingView and MetaTrader 5.
Read the pattern one bar at a time
Illustrative prices only. These five bars form an up fractal with a center high of 106. The low column is included so the same window can be checked independently for a down fractal.
| Bar | High | Low | What is known at its close |
|---|---|---|---|
| 1 | 101 | 99 | Left context only. |
| 2 | 103 | 100 | Second left bar; no center yet. |
| 3 | 106 | 102 | Candidate high. Neither right bar exists yet. |
| 4 | 104 | 101 | One lower right high. Still unconfirmed. |
| 5 | 102 | 100 | At this close, both right highs are lower. Confirm bar 3. |
The high test passes because 106 exceeds 101, 103, 104 and 102. The low test fails because the center low, 102, is not below all four other lows. For a separate down-fractal illustration, lows of 100, 98, 95, 97 and 99 would pass at the fifth close.
Now change bar 5's high to 106 or 107. The strict up pattern fails. If bar 5 first trades below 106 and later reaches it before closing, an early candidate disappears. There was never a confirmed up fractal under this example's closing-bar rule.
A past marker is not an earlier signal
A plot offset changes where a shape is displayed. It does not change when the script learned the result. With an offset of -2, the bar 5 calculation draws its triangle at bar 3. Reading that historical triangle as an entry available on bar 3 introduces future information into the decision.
Keep a separate confirmation marker with no offset. This makes it possible to compare the pattern's price location with the first bar on which its result was available. TradingView documents this distinction in its repainting guide.
Two bars of delay also means two bars of price movement before confirmation. On a continuous 15-minute chart, the second right bar closes 30 minutes after the center bar closes. Session gaps can make the elapsed time longer. Neither a negative plot offset nor a trend filter removes that waiting period.
Pine Script with visible confirmation timing
This educational indicator implements the strict five-bar rule above. UP and DN circles mark confirmation on the current bar. The optional triangles mark the center two bars earlier. It is not a full reproduction of every Williams Fractals variant.
//@version=6
indicator("Williams Fractals: strict five-bar confirmation", overlay=true)
showPastMarkers = input.bool(false, "Also mark the center bar (2 bars in the past)")
// Strict five-bar definition: equal highs or lows reject the pattern.
// The center is two bars behind the current confirmation bar.
upPattern = bar_index >= 4 and high[2] > high[4] and high[2] > high[3] and high[2] > high[1] and high[2] > high
downPattern = bar_index >= 4 and low[2] < low[4] and low[2] < low[3] and low[2] < low[1] and low[2] < low
upConfirmed = upPattern and barstate.isconfirmed
downConfirmed = downPattern and barstate.isconfirmed
// Default marks show when the pattern becomes available.
plotshape(upConfirmed, title="Up fractal confirmed now", style=shape.circle, location=location.abovebar, color=color.blue, size=size.tiny, text="UP")
plotshape(downConfirmed, title="Down fractal confirmed now", style=shape.circle, location=location.belowbar, color=color.orange, size=size.tiny, text="DN")
// Optional historical markers identify the center, not an earlier signal.
plotshape(showPastMarkers and upConfirmed, title="Up fractal center (backplotted)", style=shape.triangleup, location=location.abovebar, offset=-2, color=color.blue, size=size.tiny)
plotshape(showPastMarkers and downConfirmed, title="Down fractal center (backplotted)", style=shape.triangledown, location=location.belowbar, offset=-2, color=color.orange, size=size.tiny)
alertcondition(upConfirmed, title="Up fractal confirmed", message="A strict five-bar up fractal is confirmed. Its center is two bars ago.")
alertcondition(downConfirmed, title="Down fractal confirmed", message="A strict five-bar down fractal is confirmed. Its center is two bars ago.")- Paste the code into TradingView's Pine Editor, save it, and add it to a standard candlestick chart.
- Leave past markers disabled first. Compare the UP or DN circle with the center two bars earlier.
- Enable the center markers to compare the two locations. The circles stay on the confirmation bar.
- Create a TradingView alert, choose this indicator and one of its confirmation conditions, and select Once Per Bar Close. Adding the indicator alone does not create an active alert.
The example uses barstate.isconfirmed on the chart timeframe. It does not request another timeframe. See TradingView's alert documentation for alert creation and timing. A compilation check does not establish trading performance.
What a fractal test must keep separate
A confirmed local high can be exceeded later without invalidating the original five-bar observation. Calling that a failed fractal confuses detection with a trading prediction. A breakout strategy and a reversal strategy can use the same level for different purposes, with different failure conditions.
- Record the center price, center bar and confirmation bar as distinct values.
- For a later breakout experiment, decide whether a wick crossing or a closing price beyond the level triggers the rule.
- Specify when an unused level expires or is replaced by a newer confirmed fractal.
- If adding a trend filter, use values available at the decision time. Evaluate the filtered rule separately instead of assuming it improves results.
- For a strategy test, define exits, position sizing, transaction costs and order timing before interpreting results.
A five-bar window is a definition, not a universally best setting. Increasing the number of right-side bars increases the waiting period. Any benefit from a different setting needs evidence from the intended market and test period.
Describe the timing rules to Pineify
Pineify AI Coding Agent can turn a rule description into Pine Script. Give it the tie policy and confirmation timing alongside the plotting request, then request a syntax check and inspect the result in TradingView.
Create a Pine Script v6 indicator using strict five-bar Williams fractals. Reject equal highs and lows. Confirm only when the second right-side candle closes. Keep a confirmation marker on that candle and an optional center marker two bars back. Add separate up and down confirmation alert conditions. Explain the difference between marker position and signal availability.Open Pine Script AI Coding Agent
Educational content, not investment advice. Pattern detection and generated code do not guarantee profitable trades.
Williams Fractals questions
Sources and further reading
Official documentation checked October 16, 2026.
- TradingView: Williams fractal indicator
Five-bar structure, lag and breakout context.
- MetaTrader 5: Fractals
Central high or low and the two bars on each side.
- TradingView Pine Script: Bar states
The closing-bar behavior of barstate.isconfirmed.
- TradingView Pine Script: Repainting
Open-bar changes and plots placed into the past.
- TradingView Pine Script: Alerts
Creating alerts from conditions and choosing bar-close timing.