Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.
What Is This Strategy?
The Mesa Adaptive Trend Shift strategy is a trend-following system built on John Ehlers' MESA Adaptive Moving Average (MAMA) and its slower companion line, FAMA (the Following Adaptive Moving Average). Where most adaptive averages you may have seen — KAMA, VIDYA, FRAMA, Hull, or McGinley — change their smoothing speed based on amplitude cues such as volatility or an efficiency ratio, MAMA takes a fundamentally different route. It measures the market's dominant cycle using a Hilbert-transform quadrature pair and a homodyne discriminator, then adapts its smoothing factor to the rate of change of phase. In plain terms, when price rotates quickly through its cycle (a turning point), the average snaps toward price; when phase drifts slowly (a clean directional run), the average glides smoothly along the trend.
The strategy treats MAMA and FAMA as a self-tuning fast/slow moving-average pair. Because FAMA reacts at half the speed of MAMA, the two lines separate during trends and converge during chop. The Mesa Adaptive Trend Shift strategy reads that separation, filtered through a volatility band, to decide when the market has genuinely shifted from one regime to another — hence the "trend shift" in its name.
This is designed as a learning tool for traders who want to understand cycle-based adaptive filtering and regime detection. It is best suited to liquid, trend-prone instruments — major forex pairs, metals, and stock indices — on intraday-to-swing timeframes. Frame your study of it as a way to explore how phase-driven adaptation behaves in different market conditions, not as a shortcut to a specific outcome.
How It Works
The strategy processes one closed candle at a time, feeding each finished bar into the MESA engine. Here is what happens on every completed bar:
- Cycle measurement: The midpoint price
(High + Low) / 2is smoothed by a short weighted filter, detrended through Hilbert-transform quadrature filters, and passed to a homodyne discriminator that estimates the market's dominant cycle length. This estimate is clamped and smoothed so it stays in a sensible range (roughly 6 to 50 bars). - Adaptive alpha: The phase of the cycle and its bar-to-bar change drive a smoothing factor (
alpha). Fast phase change produces a large alpha (MAMA hugs price); slow phase change produces a small alpha (MAMA glides). TheFastLimitandSlowLimitinputs cap this factor at both ends. - Two lines: MAMA updates with the full alpha, while FAMA updates with half of it, so FAMA trails MAMA like a slower shadow.
The entry and regime logic then works as follows:
- The strategy computes the gap between the two lines:
gap = MAMA − FAMA. - It also computes a separation band:
sep = SepAtrMult × ATR, where ATR is the Average True Range (a standard measure of recent volatility). - When the gap rises above the band, the strategy signals an uptrend and shifts to a long regime.
- When the gap falls below the negative band, it signals a downtrend and shifts to a short regime.
- While the gap stays inside the band — where the two lines merely "kiss" — the strategy holds its previous regime. This ATR-scaled band creates hysteresis, so the system only acts on a genuine regime flip, not on the noise around a crossover.
On each confirmed flip:
- Entry: A long flip closes any open short and opens a new long at the ask price (if not already long). A short flip closes any open long and opens a new short at the bid price (if not already short). Only one position per direction is held at a time.
- Stop-loss: Framed by volatility — for longs,
entry − SlMult × ATR; for shorts,entry + SlMult × ATR. - Take-profit: Also volatility-scaled — for longs,
entry + TpMult × ATR; for shorts,entry − TpMult × ATR.
Because every stop and target is expressed in ATR multiples, the risk frame automatically widens in volatile markets and tightens in calm ones. The strategy also warms up (typically 60 bars) before taking any signal, giving the cycle estimate and the two adaptive lines time to stabilise.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| FastLimit | 0.50 | 0.10 | 0.90 | Upper cap on the adaptive smoothing factor. Higher values let MAMA react faster to turns. |
| SlowLimit | 0.05 | 0.01 | 0.20 | Floor on the smoothing factor. Lower values let MAMA glide more smoothly during trends. |
| SepAtrMult | 0.15 | 0.00 | 1.00 | Size of the ATR-scaled hysteresis band between MAMA and FAMA. Larger values require a wider separation before a regime flip is accepted, filtering more noise. |
| AtrPeriod | 14 | 7 | 40 | Lookback length for the Average True Range used in the band, stop, and target. |
| SlMult | 2.0 | 0.5 | 6.0 | Stop-loss distance as a multiple of ATR. |
| TpMult | 3.0 | 0.5 | 10.0 | Take-profit distance as a multiple of ATR. |
| Lots | 0.10 | 0.01 | 1.0 | Fixed trade size in lots. |

Recommended Chart Settings
The Mesa Adaptive Trend Shift strategy was designed for liquid, trend-prone instruments such as major forex pairs (for example EUR/USD or GBP/USD), metals like gold, and major stock indices. It runs on whatever primary timeframe you attach it to, and it is intended for intraday-to-swing horizons — timeframes from roughly M15 up to H4 or D1 are reasonable starting points for study.
Because the cycle estimate adapts to the instrument you run it on, no single "best" chart exists. Results will vary considerably across symbols, sessions, and market conditions. Treat any specific chart choice as a starting point for your own testing rather than a fixed recommendation, and always validate behaviour on the exact symbol and timeframe you intend to study.
How to Install on MetaTrader 5
- Download the .ex5 file from the link below
- Copy it to your MT5
MQL5\Expertsfolder - Restart MetaTrader 5 or refresh the Navigator panel
- Drag the EA onto a chart matching the recommended symbol and timeframe
- Configure the input parameters and enable Algo Trading
What to Consider Before Using This EA
Strengths. The phase-driven adaptation behind MAMA is genuinely distinct from amplitude-based adaptive averages. In sustained, clean trends the small alpha lets the line glide, which historically helps a trend-follower stay in a move rather than being shaken out by minor pullbacks. The ATR hysteresis band is a thoughtful touch — it is designed to suppress the whipsaw trades that plague simple moving-average crossovers when the two lines hover near each other.
Known limitations. Cycle-measurement techniques assume the market actually has a measurable dominant cycle. In choppy, directionless, or news-driven conditions, the phase estimate can wander, and the strategy may flip regimes more often than the underlying trend justifies. Like all trend-following systems, it can suffer a series of small losing trades during range-bound periods, giving those back to a smaller number of larger trend wins — a pattern that can be psychologically difficult to sit through. The stop-and-reverse behaviour on every flip also means the system is essentially always in the market, which increases exposure to spread and swap costs.
Where it may underperform. Expect weaker behaviour in tight ranges, during low-liquidity sessions, and around scheduled high-impact news, when volatility spikes can trigger flips that quickly reverse. The fixed lot size does not scale with account equity, and the warm-up requirement means it will not trade at all on very short data histories.
Risk Management Tips
- Test on a demo account first. Run the strategy in MT5's Strategy Tester and on a demo account across several market conditions before considering anything else.
- Risk only a small fraction per trade. A common educational guideline is to risk no more than 1–2% of your account on any single position. Size your lots so the ATR-based stop distance stays within that limit rather than leaving
Lotsat a fixed default. - Understand drawdown. Trend-following equity curves are often jagged, with strings of small losses between winners. Know the maximum losing streak you are prepared to tolerate before you begin.
- Account for costs. Because the strategy reverses on every flip, spread, commission, and swap can accumulate. Factor these into any evaluation.
- Never over-leverage. Leverage magnifies both gains and losses. Use it conservatively, and never commit capital you cannot afford to lose.
Risk Warning
Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.
Downloads
- Expert Advisor: MesaAdaptiveTrendShift.ex5 (33 downloads)
- Source Code: MesaAdaptiveTrendShift.mq5 (28 downloads)
- Documentation: MesaAdaptiveTrendShift.pdf (32 downloads)