Alligator
Bill Williams' Alligator — three smoothed averages of the median price, Jaws 13, Teeth 8 and Lips 5, each drawn shifted forward by 8, 5 and 3 bars.
It measures the spread between three horizons of the same average. The conventional readings are the three lines intertwined, described as a sleeping market, and the three fanned open in order, described as a trending one.
01The study, live
Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.
What this figure shows
The figure is computed over 300 sample bars. Alligator has no value on the first 7 — the bars it needs before it can answer — and its first value stands on bar 8. Counting the conditions the study declares on these bars: the lips crosses above the teeth 4 times; the lips crosses below the teeth 4 times. Press a condition under the figure to see each place marked. As states rather than moments: the lines are in order upward: lips, teeth, jaws on 134 bars; the lines are in order downward: lips, teeth, jaws on 125 bars.
02Its parts, named
03What you see
Three smoothed averages of the median price, each shifted forward: the jaw (13 bars, shifted 8), the teeth (8 shifted 5) and the lips (5 shifted 3). They are drawn over the candles, each in its own colour, and because of the shifts all three run on past the newest candle into the empty space to its right. When the market has been quiet the three lines lie on top of one another; when it moves they fan out in the order lips, teeth, jaw, with the lips nearest price.
04Where it comes from
Bill Williams introduced the Alligator in Trading Chaos (1995) and New Trading Dimensions (1998). His image: the alligator sleeps when the lines are tangled, wakes when they part, and eats when they are spread in order.
05The formula
Jaw = SMMA((H+L)/2, 13) shifted 8, Teeth = SMMA(·, 8) shifted 5, Lips = SMMA(·, 5) shifted 3
06A worked example
The sample bars used here are eight: closes 20, 21, 23, 22, 24, 25, 24, 26; highs 21, 22, 24, 24, 25, 26, 26, 27; lows 18, 19, 20, 21, 21, 23, 23, 23; opens 19, 20, 21, 23, 22, 24, 25, 24; volumes 100, 120, 150, 90, 140, 160, 80, 170.
Every line is a smoothed average (SMMA) of the bars' median price, (high + low) / 2: here 19.5, 20.5, 22.0, 22.5, 23.0, 24.5, 24.5, 25.0.
Take a period of 3 for one line. Its first value is the plain average of the first three medians, (19.5 + 20.5 + 22.0) / 3 = 20.67; each later value keeps two thirds of the last and adds a third of the new median: (2 × 20.67 + 22.5) / 3 = 21.28.
The value computed on a bar is then drawn some bars to the right — 8 for the Jaw, 5 for the Teeth, 3 for the Lips by default. The Jaw's point under today's bar was computed 8 bars ago; and the three lines extend past the last bar into the empty space on the right.
07Built in Assay
The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.
//@version=6 indicator("Bill Williams' Alligator", overlay = true) // Each line is a smoothed (Wilder) average of the bar's middle price... jaws = ta.rma(hl2, 13) teeth = ta.rma(hl2, 8) lips = ta.rma(hl2, 5) // ...drawn forward by its own number of bars. plot(jaws, "Jaws", offset = 8) plot(teeth, "Teeth", offset = 5) plot(lips, "Lips", offset = 3)
Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.
08Readings — what traders look for
Lines intertwined is read as a market without a trend — the sleeping alligator.
Lines opening in order (lips, teeth, jaw from top to bottom in a rise) is read as a trend under way.
The lips crossing the teeth is read as the shortest average turning against the middle one.
How "the Alligator wakes" fails. The lines fanning apart in order are read as a trend under way. Because each line is smoothed and then shifted right, the fan opens well after the move began; short moves are over before it does.
How the braid fails. Intertwined lines are read as a market with no trend, to be left alone. The braid also describes the first bars of every new trend.
09In different markets and timeframes
The Alligator shows a trend only after it is under way: three smoothed averages, each drawn several bars ahead. Williams' own advice was to stay out while the lines are braided. It needs trends that last many times its periods.
10With other studies
Read with the Gator (the gaps between its lines as a histogram), with Fractals for levels, and with the Awesome Oscillator for momentum — the set Williams designed together.
11What it does not tell you
The lines are smoothed and shifted forward; the shift draws past values ahead of the last bar, so the visible future part of the lines is made of past prices.
12Inputs and defaults
- 1Jaw period — 13The period of the slowest line (13).
- 2Jaw shift — 8How many bars to the right the Jaw is drawn (8). A shift changes where the line is drawn, not its values.
- 3Lips period — 5The period of the fastest line (5).
- 4Lips shift — 3How many bars to the right the Lips are drawn (3).
- 5Teeth period — 8The period of the middle line (8).
- 6Teeth shift — 5How many bars to the right the Teeth are drawn (5).
- 7Average — The study's ownThe kind of moving average inside the study. Left at the study's own, it is the one the study's calculation uses by itself.
- 8Price — The study's ownThe price the study reads. Left at the study's own, it is the one the study was designed on.
- 9Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 10Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.
What each input changes
- AverageThe kind of average the three lines are: smoothed (the default, Williams' own), simple, exponential or linear-weighted.
- PriceThe price the three lines are computed from. Left at the study's own it is the median price, (High + Low) / 2, which is what Williams used.
- In use13/8/5 with shifts 8/5/3 are Williams' numbers, and the study is seldom changed.
13Limits and common misreadings
Shifted lines are old values. What is drawn under the current bar was computed 3, 5 and 8 bars ago.
Three averages of one series: the three lines never disagree for long by construction.
Smoothed averages have long memory: a 13-period SMMA moves like a 25-period EMA.
14Conditions an alert or a strategy can watch
an event happens on one bar a state holds on every bar while it lasts
These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.
15Practise it in the laboratory
Put the Alligator on a chart and replay a clean trend from its first bar. Note on which bar the three lines are first in order, and how much of the move had already happened.
Open the laboratory17In Bentrix
- From the menu: a chart's Indicators button › Bill Williams › Alligator, or type Alligator in its search.
- Its settings: the settings card opens when it is added; its legend's name opens it again.
18From an agent or a program
Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "alligator"}).
The study, as a chart files it
This is a new Alligator’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.
{
"applied": "close",
"convention": "mt5",
"kind": "alligator",
"settings": {
"jaw": 13,
"jaw_shift": 8,
"lips": 5,
"lips_shift": 3,
"shape": "alligator",
"teeth": 8,
"teeth_shift": 5
}
}An agent
An agent calls the MCP tool with it:
{
"name": "study_values",
"arguments": {
"bench": "bentrix://lab/\u2026/bench/\u2026",
"symbol": "EURUSD",
"timeframe": "H1",
"limit": 5,
"study": {
"applied": "close",
"convention": "mt5",
"kind": "alligator",
"settings": {
"jaw": 13,
"jaw_shift": 8,
"lips": 5,
"lips_shift": 3,
"shape": "alligator",
"teeth": 8,
"teeth_shift": 5
}
}
}
}A program
A program does the same in its language — bench and market as in the built-in indicators guide:
Python
values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "mt5", "kind": "alligator", "settings": {"jaw": 13, "jaw_shift": 8, "lips": 5, "lips_shift": 3, "shape": "alligator", "teeth": 8, "teeth_shift": 5}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
print("line:", line["line"])
print(" newest values:", line["values"])JavaScript
const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "mt5", "kind": "alligator", "settings": { "jaw": 13, "jaw_shift": 8, "lips": 5, "lips_shift": 3, "shape": "alligator", "teeth": 8, "teeth_shift": 5 } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
console.log("line:", line.line);
console.log(" newest values:", line.values);
}C#
var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "mt5", ["kind"] = "alligator", ["settings"] = new Dictionary<string, object?> { ["jaw"] = 13, ["jaw_shift"] = 8, ["lips"] = 5, ["lips_shift"] = 3, ["shape"] = "alligator", ["teeth"] = 8, ["teeth_shift"] = 5 } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
Console.WriteLine($"line: {line!["line"]!}");
Console.WriteLine($" newest values: {line!["values"]!}");
}Go
values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "mt5", "kind": "alligator", "settings": map[string]any{"jaw": 13, "jaw_shift": 8, "lips": 5, "lips_shift": 3, "shape": "alligator", "teeth": 8, "teeth_shift": 5}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
fmt.Println("line:", at(line, "line"))
fmt.Println(" newest values:", at(line, "values"))
}Java
Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "mt5", "kind", "alligator", "settings", obj("jaw", 13, "jaw_shift", 8, "lips", 5, "lips_shift", 3, "shape", "alligator", "teeth", 8, "teeth_shift", 5))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
System.out.println("line:" + " " + at(line, "line"));
System.out.println(" newest values:" + " " + at(line, "values"));
}C++
auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "mt5"}, {"kind", "alligator"}, {"settings", Json::Object{{"jaw", 13}, {"jaw_shift", 8}, {"lips", 5}, {"lips_shift", 3}, {"shape", "alligator"}, {"teeth", 8}, {"teeth_shift", 5}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
std::cout << "line:" << " " << line["line"].dump() << std::endl;
std::cout << " newest values:" << " " << line["values"].dump() << std::endl;
}Julia
values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "mt5", "kind" => "alligator", "settings" => Dict{String,Any}("jaw" => 13, "jaw_shift" => 8, "lips" => 5, "lips_shift" => 3, "shape" => "alligator", "teeth" => 8, "teeth_shift" => 5)); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
println("line:", " ", line["line"])
println(" newest values:", " ", line["values"])
endR
values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "mt5", kind = "alligator", settings = list(jaw = 13, jaw_shift = 8, lips = 5, lips_shift = 3, shape = "alligator", teeth = 8, teeth_shift = 5)), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
cat("line:", format(line$line), "\n")
cat(" newest values:", format(line$values), "\n")
}Rust
let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "mt5", "kind": "alligator", "settings": {"jaw": 13, "jaw_shift": 8, "lips": 5, "lips_shift": 3, "shape": "alligator", "teeth": 8, "teeth_shift": 5}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
println!("line: {}", line["line"]);
println!(" newest values: {}", line["values"]);
}Reading the answer
times— the candles’ open times, in milliseconds since 1970 (UTC), oldest first.lines— one entry per line, in this order, each with itslinename and itsvalues;values[i]belongs to the candle attimes[i].- The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
nullis a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
line | What it is |
|---|---|
Jaws | jaw |
Teeth | teeth |
Lips | lips |
In a strategy
Filed under a key of your choice in a strategy document’s studies — here alligator: {"alligator": {"applied": "close", "convention": "mt5", "kind": "alligator", "settings": {"jaw": 13, "jaw_shift": 8, "lips": 5, "lips_shift": 3, "shape": "alligator", "teeth": 8, "teeth_shift": 5}}} — its rules can name:
| Write | What it is |
|---|---|
alligator.jaws | this line, as a value in a compare |
alligator.teeth | this line, as a value in a compare |
alligator.lips | this line, as a value in a compare |
{"cond": "alligator:alligator.lips_cross_up"} | a condition it declares itself |
{"cond": "alligator:alligator.lips_cross_down"} | a condition it declares itself |
{"cond": "alligator:alligator.aligned_up"} | a condition it declares itself |
{"cond": "alligator:alligator.aligned_down"} | a condition it declares itself |
19Sources
- Williams, Bill. Trading Chaos. Wiley, 1995.
- Williams, Bill. New Trading Dimensions. Wiley, 1998.
Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed