Loading…

Ehlers MAMA And FAMA Adaptive Average

Every fixed period moving average is a compromise: short enough to follow a trend and it whips on every wiggle, long enough to ignore the wiggle and it lags the trend badly. MAMA solves this by measuring, bar by bar, how fast price is actually rotating through its dominant cycle using a Hilbert transform, then using that measurement to set its own smoothing constant. When price accelerates into a trend the cycle period shortens, the smoothing constant rises toward InpFastLimit, and MAMA hugs price. When price settles into a cycle the period lengthens, the constant falls toward InpSlowLimit, and MAMA flattens out instead of chasing noise. FAMA is a second, more heavily damped stage of the same alpha, giving the crossover pair traders use the way they would a fast and slow moving average - except both are adapting together. The reason this is worth publishing rather than another simplified "MAMA style" indicator is the Hilbert transform itself. Producing the in-phase and quadrature components correctly needs a 90 degree phase-advance filter and a homodyne discriminator across two full cycles of history, each step depending on several bars back. Skip that and substitute a shortcut phase estimate - which is what most ports floating around do - and the period estimate desyncs the moment price stops looking like a clean sine wave, which is most of the time. This follows Ehlers' published sequence exactly: Smooth, Detrender, Q1/I1, the jI/jQ 90 degree advance, phasor addition, the homodyne Re/Im pair, period extraction with its clamps, then phase and alpha. Notes and limitations - The filter chain needs roughly ten bars of history before it produces a meaningful reading; earlier bars are seeded flat rather than left blank so the recursive terms have something sane to build on, but treat the first handful of bars on a short history as warm-up, not signal. - This is a smoothing and trend-following tool, not a cycle-length readout by itself - the internal dominant-cycle period is used only to drive alpha and is not plotted. - Like any adaptive filter, a sudden regime change (a gap, a news spike) can momentarily confuse the period estimate before it settles; the 1.5x/0.67x clamp on period-to-period change limits but does not eliminate this. - Values only ever use the current and older closed bars; the still-forming bar 0 is plotted from live intrabar price and will move until that bar closes, same as any other adaptive average.

Indicator · MT4 · v1.0 · Free

About Ehlers MAMA And FAMA Adaptive Average

Ehlers MAMA And FAMA Adaptive Average is an indicator for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Fast limit, Slow limit and Alerts. MQL source code included.

Files in the download: EhlersMamaFama.ex4, EhlersMamaFama.mq4, EhlersMamaFama.txt.

Settings

SettingDefaultWhat it does
Fast limit0.5Fast alpha limit (trending cap)
Slow limit0.05Slow alpha limit (cycling floor)
AlertstrueAlert once per closed bar when MAMA crosses FAMA

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Moving Average · Trend · Alerts · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria