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; last mama = %f\n", outNBElement, outBegIdx, mama[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 {}; last mama = {}", range.count, range.beg_idx, mama[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
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.println(r.count() + " values from bar " + r.begIdx() + "; last mama = " + mama[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}; last mama = {mama[r.Count - 1]}");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 + '; last outMama = ' + outMama[outMama.length - 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 |
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)