TradingView indicators

Williams Alligator: formula, offsets and signal timing

The Williams Alligator indicator applies three smoothed moving averages to median price. Its Jaw, Teeth and Lips use lengths of 13, 8 and 5, with drawings shifted right by 8, 5 and 3 bars. The shift changes where a value appears on the chart. It does not predict a future price. To code a signal, first decide whether you compare the current averages or the shifted lines visible at the current bar, then define when the signal is confirmed.

Source: HL2Smoothing: SMMALengths: 13 / 8 / 5Offsets: 8 / 5 / 3
Inspect and copy the Pine Script example

The formula separates smoothing from displacement

Bill Williams' Alligator uses SMMA, a recursive average initialized with an SMA. For a continuous price series and a length N, the first N observations provide the seed. Each later update retains (N − 1) / N of the preceding result and adds 1 / N of the latest input.

Median price = (high + low) / 2

First SMMA = sum of first N median prices / N

Next SMMA = (previous SMMA × (N − 1) + median price) / N

Conventional parameters; all three use the chart timeframe.
LineLengthRight offsetAt chart coordinate t
Jaw, blue138 barsJaw calculated at t − 8
Teeth, red85 barsTeeth calculated at t − 5
Lips, green53 barsLips calculated at t − 3

The six inputs in the example accept lengths from 1 to 100 and offsets from 0 to 100. Those limits bound this example; they are not recommended tuning ranges. Changing a length alters the smoothing. Changing only an offset alters the displayed timing. The MetaTrader calculation reference documents the conventional source and parameters.

SMMA and SMA share the seed, then diverge: SMA drops the oldest observation from a fixed window, while this SMMA carries the preceding result forward. See the SMA formula and EMA weighting example when checking a substitution.

Which value is available, and where is it drawn?

Suppose the current bar is 100. The Jaw calculated from data through bar 100 is drawn at coordinate 108 by a plot offset of +8. At coordinate 100, the visible Jaw instead comes from bar 92. Both are historical-data calculations. Neither uses bar 108's price.

Rule being evaluated at bar 100Values comparedMeaning
Current calculation alignmentjaw, teeth, lipsAll calculated through bar 100, drawn at different future coordinates
Visible alignment at bar 100jaw[8], teeth[5], lips[3]Values from bars 92, 95 and 97 at the same chart coordinate

These rules can change state on different bars. The example chooses the second rule. Using a historical index and a positive plot offset together would displace the same line twice, so the drawing uses the raw series and the rule uses the indexed series.

Current HL2 and its SMMA can change while a bar is open. The example waits for barstate.isconfirmed before showing an alignment-change marker. With all default offsets positive, its indexed line values already come from closed bars; waiting is still the stated rule, and matters when an offset is changed to zero. A marker is an observation, not an order fill. See TradingView's plot offset and bar-state documentation.

Pine Script v6 with explicit signal timing

Paste this indicator into Pine Editor and add it to the chart. It plots the three displaced lines and marks a new bullish or bearish ordering at bar close. The Data Window includes the indexed values used by the rule. There are no strategy orders, exits, position sizing or performance results in this script.

Pine Script v6
//@version=6
indicator("Williams Alligator: timing example", overlay=true)

jawLength = input.int(13, "Jaw length", minval=1, maxval=100)
teethLength = input.int(8, "Teeth length", minval=1, maxval=100)
lipsLength = input.int(5, "Lips length", minval=1, maxval=100)
jawOffset = input.int(8, "Jaw offset", minval=0, maxval=100)
teethOffset = input.int(5, "Teeth offset", minval=0, maxval=100)
lipsOffset = input.int(3, "Lips offset", minval=0, maxval=100)

smma(source, length) =>
    seed = ta.sma(source, length)
    float value = na
    value := na(value[1]) ? seed : (value[1] * (length - 1) + source) / length
    value

jaw = smma(hl2, jawLength)
teeth = smma(hl2, teethLength)
lips = smma(hl2, lipsLength)

// Positive offsets move drawings right, without reading future prices.
plot(jaw, "Jaw", color=color.blue, offset=jawOffset)
plot(teeth, "Teeth", color=color.red, offset=teethOffset)
plot(lips, "Lips", color=color.green, offset=lipsOffset)

// Values of those drawings at the current chart bar.
jawAtBar = jaw[jawOffset]
teethAtBar = teeth[teethOffset]
lipsAtBar = lips[lipsOffset]
ready = not na(jawAtBar) and not na(teethAtBar) and not na(lipsAtBar)
bullish = ready and lipsAtBar > teethAtBar and teethAtBar > jawAtBar
bearish = ready and lipsAtBar < teethAtBar and teethAtBar < jawAtBar

// A demonstration of alignment changes, not trade orders.
bullStart = barstate.isconfirmed and ready[1] and bullish and not bullish[1]
bearStart = barstate.isconfirmed and ready[1] and bearish and not bearish[1]
plotshape(bullStart, "Bullish alignment begins", shape.triangleup, location.belowbar, color.green, size=size.tiny)
plotshape(bearStart, "Bearish alignment begins", shape.triangledown, location.abovebar, color.red, size=size.tiny)
alertcondition(bullStart, "Bullish alignment begins", "Alligator bullish alignment confirmed at bar close.")
alertcondition(bearStart, "Bearish alignment begins", "Alligator bearish alignment confirmed at bar close.")

plot(jawAtBar, "Jaw at current bar", display=display.data_window)
plot(teethAtBar, "Teeth at current bar", display=display.data_window)
plot(lipsAtBar, "Lips at current bar", display=display.data_window)
  • Blue, red and green curves: the Jaw, Teeth and Lips with their respective offsets.
  • Up triangle: the visible lines first become Lips > Teeth > Jaw after the prior ready bar was not bullish.
  • Down triangle: the visible lines first become Lips < Teeth < Jaw after the prior ready bar was not bearish.
  • Markers have no plotting offset. Their location is the bar where the rule is confirmed.

Each SMMA needs its seed history. The alignment check also needs the requested history offsets. With continuous input, the default Jaw first becomes available at the current chart coordinate on the 21st loaded bar; this example requires a ready preceding bar before marking a transition. Missing input or a different dataset start can change initialization, so compare after an adequate warm-up period.

A calculation you can reproduce

This is a hypothetical sequence, not a market result. Let the first five median prices be 100, 102, 104, 106 and 108. The five-period Lips seed is 520 / 5 = 104. Then feed 110, 100 and 110 into the recurrence. Keep full precision between updates.

Calculation barMedian priceLips calculationResultDrawn at (+3)
5108520 / 51048
6110(104 × 4 + 110) / 5105.29
7100(105.2 × 4 + 100) / 5104.1610
8110(104.16 × 4 + 110) / 5105.32811

At coordinate 8 the visible Lips is 104, while the latest calculation is 105.328. A close of 104.5 would be above the visible Lips and below the current calculation. Both comparisons are possible with known data, but they implement different rules.

How entanglement defeats a simple ordering rule

For a second hypothetical test, set every median price to 100 long enough for all seeds, then alternate 101, 99, 101, 99 indefinitely. With default lengths, each SMMA approaches an alternating distance from 100 of 1 / (2N − 1): 0.04 for Jaw, 0.066667 for Teeth and 0.111111 for Lips. These are limiting values, rounded below, after the initial transient has faded.

Current input phaseVisible Jaw (+8)Visible Teeth (+5)Visible Lips (+3)State
101 phase100.04000099.93333399.888889Lips < Teeth < Jaw
99 phase99.960000100.066667100.111111Lips > Teeth > Jaw

The even Jaw offset preserves the phase; the odd Teeth and Lips offsets reverse it. The displayed ordering flips each bar while the input remains bounded between 99 and 101. A valid alignment condition therefore need not identify a sustained trend. This is a constructed counterexample, not a measured false-signal rate.

Requiring two or more consecutive aligned bars would reject these one-bar states, but introduces delay and does not prove that the next move will persist. TradingView describes repeated crossings in choppy markets in its Alligator limitations.

Check the script before defining a strategy

  1. Match the symbol, timeframe, chart type, session and history range when comparing with another implementation.
  2. Keep HL2 and default lengths fixed first. Compare line values after warm-up, then test offsets separately.
  3. Inspect the indexed Data Window values at one bar. Verify that the marker uses those values and remains on the evaluation bar.
  4. Watch an open bar and its close. If you add a price condition, specify whether it uses live price or confirmed close.
  5. Define entries, exits, sizing, fees, slippage and execution timing separately before any backtest. An indicator condition alone cannot establish profitability.

Build a checkable Alligator script with Pineify

Give the Pine Script AI Coding Agent your source, smoothing lengths, offsets and confirmation rule. Ask it to expose the intermediate values so you can compare them bar by bar in TradingView. Review the output before adding trade execution.

Example request: "Use HL2, SMA-seeded SMMA lengths 13/8/5 and plot offsets 8/5/3. Compare the shifted lines at the current chart coordinate. Confirm state changes at bar close, keep markers on that bar, and expose the compared values in the Data Window. Do not add strategy orders."

Build an Alligator script

Educational code and calculations. They are not investment advice or evidence of profitable settings.

Williams Alligator questions

It is a price overlay made from three smoothed moving averages: Jaw, Teeth and Lips. Their separation and ordering describe the relationship between slower and faster price averages. Crossings can repeat in a sideways market, so an alignment is a condition to inspect rather than proof that a trend will continue.

Use median price (high + low) / 2. Initialize each SMMA with an SMA of its length, then update it as (previous SMMA × (length − 1) + current median price) / length. The conventional lengths are 13, 8 and 5; the associated rightward drawing offsets are 8, 5 and 3 bars.

No. A positive Pine plot offset moves an already calculated point to a later chart coordinate. At bar 100, a Jaw value calculated at bar 100 can be drawn at coordinate 108. That value contains no prices from bars 101 through 108. The Jaw visible at coordinate 100 was calculated eight bars earlier.

Add Williams Alligator from the indicator search, or paste the Pine Script example into Pine Editor and add it to your chart. Match lengths and offsets before comparing the curves. The example includes Data Window values at the current chart coordinate and marks the first confirmed bar of a new ordered state. Those markers are an illustrative rule, not a complete strategy.

The answer depends on the series being compared and the confirmation rule. Current unshifted averages include the open bar and can change before it closes. Comparing the shifted lines at the current chart coordinate uses older values. The example deliberately waits for bar close in either case and leaves its signal marker on the bar where the rule is evaluated.

Start with the conventional values to verify the implementation. A useful setting depends on the instrument, timeframe and trading rule being tested. Shortening a smoothing period increases the weight of the latest input; changing an offset changes which historical value appears at a chart coordinate. These are different changes and should be tested separately.

Small alternating price moves can reorder closely spaced averages without producing a sustained trend. Requiring extra confirmation bars can reject some short-lived states, but it also delays detection and can still fail. Evaluate any filter on separate data with explicit entries, exits, fees and slippage; a compilation check cannot establish trading performance.

No. This SMMA recurrence assigns the new value a weight of 1 / length after its SMA seed. A conventional EMA uses 2 / (length + 1), so equal lengths do not give equal weighting. Replacing SMMA with EMA changes the indicator, even if the three colors and drawing offsets stay the same.

Sources and related indicators

Official documentation checked on October 17, 2026. Numerical examples are constructed on this page.

Browse TradingView indicator guides, review the SMA or EMA calculation, or compare a different displaced-line design in the Ichimoku guide.