Fractal Adaptive Moving Average (FRAMA)
Summary
Fractal Adaptive Moving Average (John Ehlers): an EMA whose smoothing factor adapts each bar to the fractal dimension of the window, estimated from the high-low ranges of the window and of its two halves. A straight run gives dimension 1 and the output follows the price; dense congestion gives dimension 2 and very slow smoothing.
Chart
Chart metadata i
Outputs
outReal:line
Formula
P[t] = (High[t] + Low[t]) / 2 R1 = range of the newer half, R2 = range of the older half, R = range of the whole window D = 1 + log2((R1 + R2) / R) alpha = exp(-4.6 * (D - 1)), at most 1; alpha = 1 when R1 or R2 is 0 FRAMA[t] = alpha * P[t] + (1 - alpha) * FRAMA[t-1], seeded with P on the bar before the first output
Notes
- Where either half of the window is flat, alpha is 1 and the output is the price; Ehlers' listing keeps the previous bar's dimension there instead.
- The period must be even; an odd period is rejected.
Inputs
inHigh— High price of each barinLow— Low price of each bar
Outputs
outReal— Adaptive moving average line
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 16 | 2–100000 | Number of bars in the window, split into two equal halves |
Properties
Numerical Stability: Initial Unstable Period
| ✅ Overlap Input i |
| ☐ Independent Y-Axis |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ✅ Uses Transcendental i |
| ☐ Input Must Be Positive |
Example
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double high[252]; /* your data, oldest first */
double low[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_FRAMA( 0, n - 1, high, low, 16, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d; last out = %f\n", outNBElement, outBegIdx, out[outNBElement - 1] );use ta_lib::Core;
let high = vec![0.0; 252]; // your data, oldest first
let low = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.frama(0, high.len() - 1, &high, &low, 16, &mut out)?;
println!("{} values from bar {}; last out = {}", range.count, range.beg_idx, out[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
double[] high = new double[252]; // your data, oldest first
double[] low = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.frama(0, high.length - 1, high, low, 16, out);
System.out.println(r.count() + " values from bar " + r.begIdx() + "; last out = " + out[r.count() - 1]);using System;
using TALib;
var high = new double[252]; // your data, oldest first
var low = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Frama(0, high.Length - 1, high, low, 16, outReal);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}; last outReal = {outReal[r.Count - 1]}");import { frama } from 'ta-lib';
const high = new Float64Array(252); // your data, oldest first
const low = new Float64Array(252); // your data, oldest first
const { begIdx, values } = frama({ high, low }, { timePeriod: 16 });
console.log(values.length + ' values from bar ' + begIdx + '; last values = ' + values[values.length - 1]);Implementation
Added in 0.8.3 (ta-lib-python 0.8.3).
TA-Lib Definition: frama.c · frama.yaml
| Native | File |
|---|---|
| C | ta_FRAMA.c |
| Rust | frama.rs |
| Java | Core_FRAMA.java |
| C# | Core_FRAMA.cs |
| TypeScript | frama.ts |
Python: talib.FRAMA (ta-lib-python 0.8.3 or later), see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Fractal Adaptive Moving Average, FrAMA
See Also
References
- John F. Ehlers, "Fractal Adaptive Moving Averages", Technical Analysis of Stocks & Commodities V.23:10 (October 2005)