WiseTrader Toolbox

MAMA

Background

MAMA is John Ehlers' MESA Adaptive Moving Average (Stocks & Commodities, 2001). It is a moving average whose smoothing speeds up and slows down automatically based on how fast the market's phase is changing, as measured by the homodyne discriminator. The result is a fast-attack / slow-decay average: it ratchets quickly to follow a real move and then holds steady until the next move, which keeps it close to price during trends while filtering out chop.

The function produces two lines: MAMA itself and a companion average called FAMA (Following Adaptive Moving Average), which uses half the adaptation speed. Because FAMA reacts more slowly, the two lines behave like a fast/slow moving-average pair — crossovers between MAMA and FAMA are the classic trade signals, similar to how a trader would use a MACD-style crossover but with far less lag and whipsaw.

Included formula

The toolbox ships a ready-made MESA Adaptive Moving Average indicator, so you can use it without writing any code. In AmiBroker open the Charts window, expand the WiseTraderToolbox group and drag MESA Adaptive Moving Average onto a price chart.

It plots the MAMA and FAMA lines over price and marks a buy where MAMA crosses above FAMA and a sell where it crosses below, with optional signal arrows. The same formula can be run as an Exploration from the Analysis window to scan a watchlist for the latest crossover. The fast and slow limits and the colours are set from the indicator's parameters.

The exported function

If you would rather build your own formula, the toolbox exports MAMA as a single AFL function you can call directly — it is the engine inside that indicator.

MAMA(Price, FastLimit, SlowLimit)
ParameterDescription
Price The price array the moving average is calculated on.
FastLimit The fastest smoothing factor MAMA is allowed to use (the upper bound on its adaptive speed). A typical value is 0.5. Must be greater than 0.
SlowLimit The slowest smoothing factor allowed (the floor on its adaptive speed). A typical value is 0.05. Must be greater than 0.
Note

MAMA does not return an array directly. Instead it writes its two result lines into AFL variables you read afterwards: MAMA_Array (the MAMA line) and FAMA_Array (the FAMA line).

Usage

MAMA( Close, 0.5, 0.05 );
mama = MAMA_Array;
fama = FAMA_Array;

Plot( mama, "MAMA", colorRed );
Plot( fama, "FAMA", colorBlue );

// Classic crossover signals
Buy  = Cross( mama, fama );
Sell = Cross( fama, mama );
Tip

Raising FastLimit makes MAMA hug price more tightly; lowering SlowLimit makes it sit flatter during quiet periods. The default pair of 0.5 / 0.05 is Ehlers' published starting point.