Bentrix Docs
HomePricingDashboard

Fractal Adaptive Moving Average FrAMA

Moving averagesoverlayone linein every package

The smoothing constant is set from the price path's fractal dimension, estimated by comparing the range of two half-windows against the whole.

It measures trend with damping proportional to how jagged the path is: a straight run is followed almost raw, a jagged one is damped hard. Read the slope, and read long flat stretches as a statement about the path's roughness. MT5 averages the applied price and TA-Lib the bar's middle, (high + low) / 2, each with its own reading of the fractal dimension, so the two lines differ by a few percent of price.

01The study, live

Live figureScroll to zoom, drag the bars to pan.
bar —O — H — L — C —FrAMA —first value at —
Show where:

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. FrAMA has no value on the first 14 — the bars it needs before it can answer — and its first value stands on bar 15. Of the 286 bars that have a value, the close is above the line on 134 and below it on 152. Counting the conditions the study declares on these bars: price crosses above the line 25 times; price crosses below the line 25 times. Press a condition under the figure to see each place marked. As states rather than moments: price is above the line on 134 bars; price is below the line on 152 bars.

02Its parts, named

Warm-upno value on the first 14 bars: thestudy needs them before it cananswerThe linethe study's value, one for each barThe bars it readseach bar's close, unless you chooseanother price
Computed by Bentrix’s own code over the sample bars. It is drawn on once, as you reach the figure.

03What you see

An average whose speed changes with the market: fast when price covers new ground, slow when it goes back over the same ground.

FrAMA is a single line on the price pane: an EMA whose speed is set, bar by bar, by how jagged the price path has been over the window.

04Where it comes from

John Ehlers described FRAMA, the Fractal Adaptive Moving Average, in 2005. Its speed follows the fractal dimension of the price series over the window: a measure of how much of the window's ground price went over twice. A path that covers new ground steadily has a dimension near 1 and gives a quick line; a jagged path that keeps retracing has a dimension near 2 and gives a line that hardly moves.

05The formula

An EMA with a changing constant:

FRAMAt=FRAMAt−1+αt(Pt−FRAMAt−1)
Ptthe applied price of bar t — the close by default
αtthis bar's smoothing constant, from the window's fractal dimension
FRAMAt−1the average one bar before

αt is taken from the fractal dimension D of the window, measured from the ranges of its two halves against the range of the whole: αt=exp(−4.6(D−1)).

06A worked example

The study compares the range of the two halves of the window with the range of the whole. Take a window of 8 bars: R₁ is the high-to-low range of the newest four, R₂ that of the four before, and R the range of all eight. The constant is

α = exp(−4.6 × log₂((R₁ + R₂) / R))

Suppose each half spans 4.0 points and the whole also spans 4.0 — price going over the same ground twice. (R₁ + R₂) / R = 2, its base-2 logarithm is 1, and α = exp(−4.6) = 0.01: the line barely moves.

Suppose instead the halves span 3.0 each and the whole 5.0 — the second half reached new ground but overlapped the first. (3 + 3) / 5 = 1.2, log₂ 1.2 = 0.263, and α = exp(−4.6 × 0.263) = 0.30: the line moves 30 % of the way to the new price.

And if the halves do not overlap at all — 2.0 and 2.0 inside a whole of 4.0 or more, a clean run — the line is set straight to price. The price it follows is the middle of each bar, (high + low) / 2.

On real bars: take eight with highs 21, 22, 24, 24, 25, 26, 26, 27 and lows 18, 19, 20, 21, 21, 23, 23, 23, whose middles are 19.5, 20.5, 22.0, 22.5, 23.0, 24.5, 24.5, 25.0. A FRAMA of period 4 reads 23.01 on the last bar, against that bar's middle of 25.00.

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.

THE SCRIPT’S GRAPH
//@version=6
indicator("Fractal Adaptive Moving Average", overlay = true)
length = input.int(14, "Length")
half = math.floor(length / 2)
price = hl2
// The range of the newest half of the window, and of the half before it.
high1 = ta.highest(high, half)
low1 = ta.lowest(low, half)
high2 = high1[half]
low2 = low1[half]
range1 = high1 - low1
range2 = high2 - low2
// The range of the whole window.
rangeAll = math.max(high1, high2) - math.min(low1, low2)
var float frama = na
if bar_index == length - 1
    frama := price
else if bar_index >= length
    if range1 > 0 and range2 > 0 and range1 + range2 > rangeAll
        // A smooth run (the halves add up to the whole) moves the average fast; a choppy one slowly.
        alpha = math.exp(-4.6 / math.log(2) * math.log((range1 + range2) / rangeAll))
        frama := alpha * price + (1 - alpha) * frama
    else
        frama := price
plot(bar_index >= length ? frama : na, "FRAMA")

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, and the line's slope.

Fast in trends, still in ranges. A line that hugs price is read as a market covering new ground; a flat line as a market retracing itself. It fails at transitions: the dimension is measured over the whole window, so the line is late to slow down when a trend ends and late to speed up when a range breaks.

09In different markets and timeframes

FRAMA is quick where price covers new ground and nearly still where it retraces — at its best in markets that move in clean legs with pauses. Where a leg is jagged, the measured dimension is high throughout and the line lags like a slow average.

10With other studies

Read beside a fixed EMA of the same period: where FRAMA flattens while the EMA still slopes, the window has been retracing. Its adaptive constant makes it a natural partner for the Choppiness Index, which measures a closely related quantity.

11What it does not tell you

!

Adapting to the past window's character is still describing the past window.

12Inputs and defaults

FrAMA (14, 0)settings card
1Period14
2Shift0
3Applied priceClose
4TimeframeChart
5CalculationTA-Lib
6Wait for the candle to closeOn
  1. 1
    Period — 14The window whose halves are compared. It has to be even; a longer window measures the character of a longer stretch and changes speed less often.
  2. 2
    Shift — 0Draws every line that many candles to the right (a negative number: to the left). The values are not changed, only where they stand.
  3. 3
    Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.
  4. 4
    Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
  5. 5
    Calculation — TA-LibOr MT5, which computes it as MetaTrader 5 does — see the calculation convention below.
  6. 6
    Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.

What each input changes

  • ShiftDraws the line that many candles to the right, or to the left with a negative number. Its values do not change — only the candle each one stands on.
  • In use16 is Ehlers' default; the period has to be even. 8 to 30 are used; shorter windows measure the dimension of very few bars and are unstable.

13Calculation convention

This is one of the studies whose result differs between the two conventions Bentrix offers. The difference is in how the first values are seeded and how the series is smoothed, so the two agree after the warm-up and differ at its start. Choose it on the settings card's Calculation row.

defaultTA-Lib

The convention of the TA-Lib library, which most charting software follows.

MT5

Computed as MetaTrader 5 computes it, so a value matches the terminal's own.

14Limits and common misreadings

Uses highs and lows, not only closes, to measure the ranges; a single spike can change the dimension of a whole window.

The mapping to speed is steep. Small changes of the dimension near 1 change the line a great deal.

15Conditions an alert or a strategy can watch

price crosses above the line eventprice crosses below the line eventprice is above the line stateprice is below the line state

Event: the bar it happens on an event happens on one barState: every bar while it holds 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.

16Practise it in the laboratory

Put FrAMA 16 and EMA 16 on one chart, replay a trend that runs into a range, and note how many bars pass before FrAMA flattens.

Open the laboratory

18On pages of their own

19In Bentrix

  • From the menu: a chart's Indicators button › Moving averages › FrAMA, or type FrAMA in its search.
  • Its settings: the settings card opens when it is added; its legend's name opens it again.

20From 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": "frama"}).

The study, as a chart files it

This is a new FrAMA’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": "frama",
  "settings": {
    "period": 14,
    "shape": "period"
  }
}

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": "frama",
      "settings": {
        "period": 14,
        "shape": "period"
      }
    }
  }
}

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": "frama", "settings": {"period": 14, "shape": "period"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
    print("line:", line["line"])
    print("  newest values:", line["values"])

JSJavaScript

const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "talib", "kind": "frama", "settings": { "period": 14, "shape": "period" } }, 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#C#

var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "talib", ["kind"] = "frama", ["settings"] = new Dictionary<string, object?> { ["period"] = 14, ["shape"] = "period" } }, 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"]!}");
}

GOGo

values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "talib", "kind": "frama", "settings": map[string]any{"period": 14, "shape": "period"}}, 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", "frama", "settings", obj("period", 14, "shape", "period"))).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++C++

auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "talib"}, {"kind", "frama"}, {"settings", Json::Object{{"period", 14}, {"shape", "period"}}}}).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" => "frama", "settings" => Dict{String,Any}("period" => 14, "shape" => "period")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
    println("line:", " ", line["line"])
    println("  newest values:", " ", line["values"])
end

RR

values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "talib", kind = "frama", settings = list(period = 14, shape = "period")), 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")
}

RRust

let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "talib", "kind": "frama", "settings": {"period": 14, "shape": "period"}})).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 its line name and its values; values[i] belongs to the candle at times[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.
  • null is a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
lineWhat it is
Mainline

In a strategy

Filed under a key of your choice in a strategy document’s studies — here frama: {"frama": {"applied": "close", "convention": "talib", "kind": "frama", "settings": {"period": 14, "shape": "period"}}} — its rules can name:

WriteWhat it is
framaits main line, as a value in a compare
{"cond": "frama:price.cross_up"}a condition it declares itself
{"cond": "frama:price.cross_down"}a condition it declares itself
{"cond": "frama:price.above"}a condition it declares itself
{"cond": "frama:price.below"}a condition it declares itself

21Sources

  1. Chande, Tushar S. "Adapting Moving Averages to Market Volatility." Technical Analysis of Stocks & Commodities, March 1992.
  2. Ehlers, John F. Rocket Science for Traders. Wiley, 2001.
  3. Ehlers, John F. "FRAMA — Fractal Adaptive Moving Average." Technical Analysis of Stocks & Commodities, October 2005.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed