MESA Adaptive Moving Average MAMA
The smoothing follows the dominant cycle's phase rate measured by a Hilbert transform, bounded by the fast and slow limits you set, with a slower FAMA drawn behind it.
It measures trend at a speed derived from the market's own cycle rather than from a fixed period. The reading is the pair: MAMA and FAMA together, and the crossings between them.
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. MAMA has no value on the first 32 — the bars it needs before it can answer — and its first value stands on bar 33. Counting the conditions the study declares on these bars: price crosses above the line 18 times; price crosses below the line 19 times. Press a condition under the figure to see each place marked. As states rather than moments: price is above the line on 120 bars; price is below the line on 148 bars.
02Its parts, named
03What you see
MAMA and its follower FAMA, with the fast and slow limits of its adaptation.
MAMA draws two lines on the price pane: MAMA itself, which moves in steps — fast when the measured cycle phase is changing quickly, slow otherwise — and FAMA, a slower follower of it.
04Where it comes from
John Ehlers published MAMA, the MESA Adaptive Moving Average, in 2001, out of his work on the Hilbert transform. It adapts to the rate at which the measured phase of the market's dominant cycle advances: a phase that moves quickly gives a quick line. It comes with a slower follower, FAMA (the Following Adaptive Moving Average), drawn beside it.
05The formula
An EMA with a changing constant:
MAMAₜ = MAMA_(t−1) + αₜ (Pₜ − MAMA_(t−1))
is the fast limit divided by the change of the Hilbert phase since the last bar, kept between the fast and the slow limit; FAMA follows MAMA with half that constant.
06A worked example
The cycle measurement is a chain of filters and cannot be carried by hand; the last step can. MAMA's constant is the fast limit divided by the change of phase (in degrees) since the last bar, kept between the two limits.
With the default limits 0.5 and 0.05: if the phase advanced 10° on this bar, α = 0.5 / 10 = 0.05 — the slow limit. If it advanced 2°, α = 0.5 / 2 = 0.25. If it advanced 1° or less, α is capped at 0.5.
Suppose MAMA stood at 100.00, the new price is 101.00 and α = 0.25: MAMA moves to 100.00 + 0.25 × 1.00 = 100.25. FAMA follows with half that constant, 0.125, toward MAMA: from 100.00 it moves to 100.00 + 0.125 × 0.25 = 100.03.
Computed by Bentrix on a known wave: on Bentrix's hundred-bar sample wave — closes of 100 + 0.05 i + 2 sin(2π i / 20) for bars i = 0 to 99, a 20-bar wave two points high on a slow rise, each bar opening at the close before, its high and low half a point beyond its body — with the default limits, MAMA reads 103.65 on the last bar and FAMA 103.16, where the close is 104.33.
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("MESA Adaptive Moving Average", overlay = true) fastLimit = input.float(0.5, "Fast limit") slowLimit = input.float(0.05, "Slow limit") // The average's speed follows the measured phase of the dominant cycle; FAMA follows MAMA at half its speed. [mama, fama] = talib.MAMA(close, fastLimit, slowLimit) plot(mama, "MAMA") plot(fama, "FAMA")
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
Read as a moving average that flattens in ranges: price against the line, the line's slope, and the MAMA line crossing its FAMA follower.
MAMA crossing FAMA. Read as a change of direction that the adaptive line has accepted; the two lines seldom cross in a range because both go flat. It fails when the cycle measurement is unstable — on thin or gappy data the phase jumps and the lines step for no visible reason.
Steps. MAMA moves in visible steps; a new step is read as the phase having snapped forward. It fails as a measure of size: a step says the constant changed, not that the move is large.
09In different markets and timeframes
MAMA is built for cycling markets: it moves in steps as the measured phase snaps forward, and its follower crosses it at changes of direction. In a market with no measurable cycle the phase is erratic and so are the steps.
10With other studies
Read with its own follower, FAMA — the pair is the study — and beside the Hilbert studies it shares its engine with (the dominant cycle period and the sine wave).
11What it does not tell you
Adapting to the past window's character is still describing the past window.
12Inputs and defaults
- 1Fast period — 0.5The fast limit: the largest smoothing constant the line may use (0.5 by default — half of each new price). It is a constant, not a number of bars.
- 2Slow period — 0.05The slow limit: the smallest constant the line may use (0.05 by default). Smaller: flatter while the market cycles.
- 3Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.
- 4Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 5Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.
The settings in use
- In useFast limit 0.5 and slow limit 0.05 are Ehlers'. A lower slow limit flattens the line further between steps.
13Limits and common misreadings
Needs history. The Hilbert transform inside uses some 32 bars before its first value and longer before it settles.
The limits are not periods. 0.5 and 0.05 are smoothing constants.
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 MAMA with its defaults on a chart and replay a range that turns into a trend; note that the two lines lie flat together in the range and separate when the trend starts.
Open the laboratory17In Bentrix
- From the menu: a chart's Indicators button › Moving averages › MAMA, or type MAMA 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": "mama"}).
The study, as a chart files it
This is a new MAMA’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": "talib",
"kind": "mama",
"settings": {
"fast": 0.5,
"shape": "mama",
"slow": 0.05
}
}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": "talib",
"kind": "mama",
"settings": {
"fast": 0.5,
"shape": "mama",
"slow": 0.05
}
}
}
}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": "talib", "kind": "mama", "settings": {"fast": 0.5, "shape": "mama", "slow": 0.05}}, 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": "talib", "kind": "mama", "settings": { "fast": 0.5, "shape": "mama", "slow": 0.05 } }, 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"] = "talib", ["kind"] = "mama", ["settings"] = new Dictionary<string, object?> { ["fast"] = 0.5, ["shape"] = "mama", ["slow"] = 0.05 } }, 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": "talib", "kind": "mama", "settings": map[string]any{"fast": 0.5, "shape": "mama", "slow": 0.05}}, 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", "talib", "kind", "mama", "settings", obj("fast", 0.5, "shape", "mama", "slow", 0.05))).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", "talib"}, {"kind", "mama"}, {"settings", Json::Object{{"fast", 0.5}, {"shape", "mama"}, {"slow", 0.05}}}}).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" => "talib", "kind" => "mama", "settings" => Dict{String,Any}("fast" => 0.5, "shape" => "mama", "slow" => 0.05)); 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 = "talib", kind = "mama", settings = list(fast = 0.5, shape = "mama", slow = 0.05)), 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": "talib", "kind": "mama", "settings": {"fast": 0.5, "shape": "mama", "slow": 0.05}})).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 |
|---|---|
Main | line |
Follower | signal |
In a strategy
Filed under a key of your choice in a strategy document’s studies — here mama: {"mama": {"applied": "close", "convention": "talib", "kind": "mama", "settings": {"fast": 0.5, "shape": "mama", "slow": 0.05}}} — its rules can name:
| Write | What it is |
|---|---|
mama | its main line, as a value in a compare |
mama.follower | this line, as a value in a compare |
{"cond": "mama:price.cross_up"} | a condition it declares itself |
{"cond": "mama:price.cross_down"} | a condition it declares itself |
{"cond": "mama:price.above"} | a condition it declares itself |
{"cond": "mama:price.below"} | a condition it declares itself |
19Sources
- Chande, Tushar S. "Adapting Moving Averages to Market Volatility." Technical Analysis of Stocks & Commodities, March 1992.
- Ehlers, John F. Rocket Science for Traders. Wiley, 2001.
- Ehlers, John F. "FRAMA — Fractal Adaptive Moving Average." Technical Analysis of Stocks & Commodities, October 2005.
- Ehlers, John F. "MAMA — The Mother of Adaptive Moving Averages." Technical Analysis of Stocks & Commodities, September 2001.
Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed