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.
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
| Line | Length | Right offset | At chart coordinate t |
|---|---|---|---|
| Jaw, blue | 13 | 8 bars | Jaw calculated at t − 8 |
| Teeth, red | 8 | 5 bars | Teeth calculated at t − 5 |
| Lips, green | 5 | 3 bars | Lips 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 100 | Values compared | Meaning |
|---|---|---|
| Current calculation alignment | jaw, teeth, lips | All calculated through bar 100, drawn at different future coordinates |
| Visible alignment at bar 100 | jaw[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.
//@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 bar | Median price | Lips calculation | Result | Drawn at (+3) |
|---|---|---|---|---|
| 5 | 108 | 520 / 5 | 104 | 8 |
| 6 | 110 | (104 × 4 + 110) / 5 | 105.2 | 9 |
| 7 | 100 | (105.2 × 4 + 100) / 5 | 104.16 | 10 |
| 8 | 110 | (104.16 × 4 + 110) / 5 | 105.328 | 11 |
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 phase | Visible Jaw (+8) | Visible Teeth (+5) | Visible Lips (+3) | State |
|---|---|---|---|---|
| 101 phase | 100.040000 | 99.933333 | 99.888889 | Lips < Teeth < Jaw |
| 99 phase | 99.960000 | 100.066667 | 100.111111 | Lips > 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
- Match the symbol, timeframe, chart type, session and history range when comparing with another implementation.
- Keep HL2 and default lengths fixed first. Compare line values after warm-up, then test offsets separately.
- Inspect the indexed Data Window values at one bar. Verify that the marker uses those values and remains on the evaluation bar.
- Watch an open bar and its close. If you add a price condition, specify whether it uses live price or confirmed close.
- 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 scriptEducational code and calculations. They are not investment advice or evidence of profitable settings.
Williams Alligator questions
Sources and related indicators
Official documentation checked on October 17, 2026. Numerical examples are constructed on this page.
- MetaTrader 5: Alligator calculation: Median price, line lengths and drawing shifts.
- TradingView: Williams Alligator: Smoothing, line interpretation and choppy-market limitations.
- TradingView Pine Script: Plots: Positive and negative plot offsets.
- TradingView: Exponential Moving Average: EMA weighting for the comparison in the FAQ.
- TradingView Pine Script: Bar states: Confirmation on the closing update of a realtime bar.
Browse TradingView indicator guides, review the SMA or EMA calculation, or compare a different displaced-line design in the Ichimoku guide.