TradingView indicator calculations

MESA Adaptive Moving Average: MAMA and FAMA

The MESA Adaptive Moving Average (MAMA) changes its smoothing coefficient using measured phase changes. FAMA, the Following Adaptive Moving Average, smooths MAMA with half that coefficient. John Ehlers developed the pair. On TradingView, identify the script author and calculation before comparing values or using a crossover: the indicator name alone does not specify an implementation.

See the decision guide

Trace phase changes into the smoothing coefficient

In the public Ehlers listing, a weighted price smoother and Hilbert-transform calculations produce in-phase I and quadrature Q components. Phase is arctan(Q/I) in degrees. The following equations describe the final adaptive stage; brackets denote the preceding bar. The suggested limits are fast = 0.5 and slow = 0.05.

  • Require 0 < slow ≤ fast ≤ 1. Because d ≥ 1, α cannot exceed fast under these constraints. These are coefficient limits, not lengths such as 5 or 50 bars.
  • Preserve the phase convention. The original half-cycle arctangent wrap can produce a negative difference, which the floor converts to 1. Using an absolute difference or replacing arctan with atan2 changes the algorithm.
  • A port must convert radians to degrees before applying the 1-degree floor. The period estimator also has its own bounds and smoothing; those intermediate rules are in the linked original listing.
  • Flat or irregular input need not contain a stable cycle. A computed phase is an estimator output, not evidence that a recurring market period exists. Near-zero I or Q makes the division and fallback policy worth inspecting.
QuantityCalculation
Phase differenced = max(1, phase[1] − phase)
Adaptive coefficientα = max(slow, fast / d)
MAMAM = α × price + (1 − α) × M[1]
FAMAF = (α / 2) × M + (1 − α / 2) × F[1]

Recalculate one bar at three adaptation speeds

Assume price = 104, previous MAMA = 100 and previous FAMA = 99, with limits 0.5 and 0.05. Each row restarts from those same hypothetical values. The phase differences are supplied inputs to this arithmetic example, not measurements from a market chart or a complete Hilbert calculation.

  • For d = 5, MAMA = 0.1 × 104 + 0.9 × 100 = 100.4. FAMA then uses that new value: 0.05 × 100.4 + 0.95 × 99 = 99.07.
  • With these limits, any d ≥ 10 reaches the 0.05 floor. Increasing the phase difference further does not make this stage slower.
  • At the same previous average of 100, a fixed 20-period EMA uses α = 2/21 and produces 100.380952. MAMA can move more or less than that EMA on this bar; the name adaptive does not establish which line always leads.
Raw phase differenceBounded d / αNew MAMANew FAMA
1 degree1 / 0.5102.00099.750
5 degrees5 / 0.1100.40099.070
20 degrees20 / 0.05100.20099.030
−170 degrees at a wrap1 / 0.5102.00099.750

Compare lag in trends and cycles

A fixed EMA applies the same coefficient on every bar. MAMA changes it after measuring the input, while FAMA adds another smoothing stage. Consequently, the pair has no single delay that applies to all waveforms. These comparisons describe the equations, not a measured trading advantage.

  • Using N = 2/α − 1, coefficients 0.5 and 0.05 correspond to fixed EMA coefficients for lengths 3 and 39. This is a one-bar coefficient comparison, not proof that MAMA behaves like an EMA with a continuously changing integer length.
  • To compare fairly, hold the symbol, source, timeframe and sessions constant. Record the price-to-line difference and bars between a specified price event and each crossing; do not infer lag from visually shifting a plot.
Input behaviorFixed EMAMAMA and FAMA
Sustained directional moveA short EMA responds faster but smooths less.A large α closes the price gap faster; a small α retains more history. Trend labels alone do not set α.
Repeated cyclesResponse depends on the chosen length and cycle frequency.Phase differences and wraps can alternate slow updates with larger steps. FAMA follows those steps more slowly.
Abrupt reversal or gapThe prior state delays the response.Previous states and the measured coefficient still affect timing; a crossover can arrive after much of the move.
Choppy, low-amplitude movementShort lengths can cross frequently.Changing α does not rule out repeated or economically unhelpful crosses. Costs can exceed small moves.

Define the crossover and the decision time

An upward crossover requires current MAMA > current FAMA and previous MAMA ≤ previous FAMA. A downward crossover requires current MAMA < current FAMA and previous MAMA ≥ previous FAMA. Equality on the current bar is neither event. A rule that stays true while MAMA is above FAMA is a different condition.

  • Hypothetical upward cross: previous MAMA = 100 and FAMA = 101, price = 104, α = 0.5. The next values are 102 and 101.25, so the event occurs. With α = 0.05 instead, they are 100.2 and 100.98, so it does not.
  • For a chart-timeframe alert, evaluate the event only when that bar closes and use Once Per Bar Close. A developing high, low or close can otherwise produce a temporary cross that disappears before the close.
  • Create the running alert after verifying the chart inputs. TradingView stores a snapshot of the script and settings for an alert; recreate it after changes. Confirming a chart bar does not by itself confirm data requested from a higher timeframe.
  • A cross defines a signal timestamp, not an order fill or an exit policy. Position size, stop rules, fees, slippage and execution timing require separate decisions before testing a strategy.

Check initialization and numerical agreement on TradingView

Select an open-source MAMA indicator and record its author, revision, source and limits. The linked LazyBear publication is one public implementation to inspect, not proof that every script bearing the name is identical. Compare both lines in the Data Window at the same completed timestamps.

  • Start with standard candles and the same input series. The original price input is the high-low midpoint; close is a different input. Changing chart type or sessions also changes the observations.
  • Record the seeds for MAMA, FAMA and the phase/period states, the first computed bar, and behavior when I = 0 or an input is missing. Do not silently replace unavailable prices with zero.
  • For a new implementation, state a seed policy explicitly, such as seeding the averages from the first valid price. That is a documented choice, not a claim of exact equivalence to the original platform initialization.
  • Load more earlier history and compare the same later bars again. Recursive startup effects can remain after the first nonempty output. Suppress signals until the chosen tolerance is met; a fixed warm-up count alone does not prove agreement.
  • If the two lines disagree, inspect phase units, the sign of the phase difference and use of current MAMA in FAMA before changing trading rules. Log intermediate phase and α values to isolate the first divergence.

Give Pineify the public algorithm and acceptance checks

Use the Pine Script AI Coding Agent to draft or review a port of the public Ehlers algorithm. Include the original listing, price source, limit constraints, phase units, initialization policy and completed-bar crossover definition. Request intermediate diagnostic values and use the arithmetic tables above to check the final smoothing stage.

  • Inspect the generated Pine Script and request a syntax check where your plan supports it. Then compare MAMA, FAMA and event timestamps against the selected TradingView implementation before creating alerts.
  • Supply public source or code you have permission to use. A matching indicator name does not authorize copying protected source, and a syntax check does not establish numerical equivalence or profitable trading.
Where Pineify fits

Pine Script AI Coding Agent

Draft or review MAMA and FAMA from a public algorithm with explicit phase units, initialization and bar-close conditions. Verify the resulting values on TradingView before enabling alerts.

Draft a MAMA and FAMA script

Frequently asked questions

Educational information, not investment advice. Examples are hypothetical calculations, not backtest results. Adaptive averages and confirmed crossovers do not guarantee returns or prevent losses.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.