MESA Adaptive Moving Average (MAMA)

Calculate the MESA Adaptive Moving Average (MAMA) and the Following Adaptive Moving Average (FAMA): averages that adapt to the speed of the prices’ cycle, so they follow fast moves and stay flat in a range.

MAMA is an exponential moving average whose smoothing factor follows the rate at which the phase of the price cycle changes, measured with the Hilbert transform. When the phase jumps, as at the start of a move, the smoothing factor is the fast limit and MAMA follows the price closely; when the phase advances slowly, the factor falls towards the slow limit and MAMA flattens. FAMA applies half the smoothing factor to MAMA, so that it follows MAMA, and Ehlers reads the crossings of the two lines as changes of direction.

The formula is as follows:

\[\text{Smooth} = \frac{4 \cdot \text{Price} + 3 \cdot \operatorname{Price}(t-1) + 2 \cdot \operatorname{Price}(t-2) + \operatorname{Price}(t-3)}{10}\] \[I_{1} \;\text{and}\; Q_{1} = \text{the In Phase and Quadrature components} \;(\text{see the Hilbert Transform Phasor Components})\] \[\text{Phase} = \operatorname{arctan}\left(\frac{Q_{1}}{I_{1}}\right) \;\text{in degrees}\] \[\text{Delta Phase} = \operatorname{Phase}(t-1) - \text{Phase},\;\; \text{at least 1}\] \[\text{Alpha} = \frac{\text{Fast Limit}}{\text{Delta Phase}},\;\; \text{at least the Slow Limit}\] \[\text{MAMA} = \text{Alpha} \cdot \text{Price} + (1 - \text{Alpha}) \cdot \operatorname{MAMA}(t-1)\] \[\text{FAMA} = 0.5 \cdot \text{Alpha} \cdot \text{MAMA} + (1 - 0.5 \cdot \text{Alpha}) \cdot \operatorname{FAMA}(t-1)\]

Also known as: MAMA, FAMA, MESA adaptive moving average.

Example · AAPL, MSFT · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_mesa_adaptive_moving_average:

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_mesa_adaptive_moving_average().xs("AAPL", level=1, axis="columns")

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

How did the MESA Adaptive Moving Average of Apple and its following average move in 2025?

Which returns:

Parameters

get_mesa_adaptive_moving_average accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Options are: “intraday” (intraday prices), “daily” (daily prices), “weekly” (weekly prices), “monthly” (monthly prices), “quarterly” (quarterly prices), “yearly” (yearly prices). Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”."Close"
fast_limitfloatThe largest smoothing factor, used when the phase jumps. Defaults to 0.5, Ehlers’ value.
slow_limitfloatThe smallest smoothing factor, used when the phase advances slowly. Defaults to 0.05, Ehlers’ value.
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the MESA adaptive moving average. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Ehlers, J.F. (2001). “MESA Adaptive Moving Averages.” Technical Analysis of Stocks & Commodities, September 2001.
  • Paper Ehlers, J.F. (2001). “Rocket Science for Traders: Digital Signal Processing Applications.” John Wiley & Sons.
  • Library Referenced against TA-Lib’s MAMA
  • Library Shares similar logic as pandas-ta-classic’s mama
Share