MESA Adaptive Moving Average (MAMA)
Summary
MESA Adaptive Moving Average: an adaptive EMA whose smoothing factor is driven by the dominant-cycle phase rate measured with a Hilbert transform. Emits two lines, MAMA and its slower follower FAMA. MAMA crossing above FAMA is bullish; crossing below is bearish.
Chart
Chart metadata i
Outputs
outMAMA:lineoutFAMA:dash_line
Formula
phase = atan(Q1/I1) in degrees; deltaPhase = max(1, prevPhase - phase) alpha = max(fastLimit/deltaPhase, slowLimit) if deltaPhase>1 else fastLimit MAMA = alpha*price + (1-alpha)*MAMA_prev FAMA = (alpha/2)*MAMA + (1-alpha/2)*FAMA_prev
Inputs
inReal— Price series to smooth
Outputs
outMAMA— Adaptive moving average (fast line)outFAMA— Following adaptive moving average, using half the alpha (slow line)
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInFastLimit | real | 0.5 | 0.01–0.99 | Upper bound on the adaptive smoothing factor |
optInSlowLimit | real | 0.05 | 0.01–0.99 | Lower bound on the adaptive smoothing factor |
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 series[252]; /* your data, oldest first */
double mama[252], fama[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_MAMA( 0, n - 1, series, 0.5, 0.05, &outBegIdx, &outNBElement, mama, fama );
printf( "%d values from bar %d:\n", outNBElement, outBegIdx );
printf( "mama = [%.4f, ..., %.4f]\n", mama[0], mama[outNBElement - 1] );
printf( "fama = [%.4f, ..., %.4f]\n", fama[0], fama[outNBElement - 1] );use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut mama = vec![0.0; 252];
let mut fama = vec![0.0; 252];
let core = Core::new();
let range = core.mama(0, series.len() - 1, &series, 0.5, 0.05, &mut mama, &mut fama)?;
println!("{} values from bar {}:", range.count, range.beg_idx);
println!("mama = [{:.4}, ..., {:.4}]", mama[0], mama[range.count - 1]);
println!("fama = [{:.4}, ..., {:.4}]", fama[0], fama[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
import java.util.Locale;
double[] series = new double[252]; // your data, oldest first
double[] mama = new double[252];
double[] fama = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.mama(0, series.length - 1, series, 0.5, 0.05, mama, fama);
System.out.printf(Locale.ROOT, "%d values from bar %d:%n", r.count(), r.begIdx());
System.out.printf(Locale.ROOT, "mama = [%.4f, ..., %.4f]%n", mama[0], mama[r.count() - 1]);
System.out.printf(Locale.ROOT, "fama = [%.4f, ..., %.4f]%n", fama[0], fama[r.count() - 1]);using System;
using TALib;
var series = new double[252]; // your data, oldest first
var mama = new double[252];
var fama = new double[252];
var core = Core.Default;
OutRange r = core.Mama(0, series.Length - 1, series, 0.5, 0.05, mama, fama);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}:");
Console.WriteLine(FormattableString.Invariant($"mama = [{mama[0]:F4}, ..., {mama[r.Count - 1]:F4}]"));
Console.WriteLine(FormattableString.Invariant($"fama = [{fama[0]:F4}, ..., {fama[r.Count - 1]:F4}]"));import { mama } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, outMama, outFama } = mama(series, {
fastLimit: 0.5,
slowLimit: 0.05,
});
console.log(outMama.length + ' values from bar ' + begIdx + ':');
console.log('outMama = [' + outMama[0]?.toFixed(4) + ', ..., ' + outMama[outMama.length - 1]?.toFixed(4) + ']');
console.log('outFama = [' + outFama[0]?.toFixed(4) + ', ..., ' + outFama[outFama.length - 1]?.toFixed(4) + ']');import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
series := make([]float64, 252) // your data, oldest first
mama := make([]float64, 252)
fama := make([]float64, 252)
core := talib.NewCore()
r, err := core.MAMA(0, len(series)-1, series, 0.5, 0.05, mama, fama)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d:\n", r.NBElement, r.BegIdx)
fmt.Printf("mama = [%.4f, ..., %.4f]\n", mama[0], mama[r.NBElement-1])
fmt.Printf("fama = [%.4f, ..., %.4f]\n", fama[0], fama[r.NBElement-1])Implementation
Added in 0.4.0.
TA-Lib Definition: mama.c · mama.yaml
| Native | File |
|---|---|
| C | ta_MAMA.c |
| Rust | mama.rs |
| Java | Core_MAMA.java |
| C# | Core_MAMA.cs |
| TypeScript | mama.ts |
| Go | mama.go |
Python: talib.MAMA, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
MESA Adaptive Moving Average, Ehlers MAMA
See Also
MA · WMA · HT_DCPERIOD
References
- John F. Ehlers, Rocket Science for Traders: Digital Signal Processing Applications, John Wiley & Sons (ISBN 0471405671)