Back to Guides
Guide

Zero Lag Moving Average Formula, and What It Removes

The zero lag moving average formula is ZLEMA = EMA(close + (close - close[lag]), n). On a straight line its lag really is zero, but only at odd periods.

The zero lag moving average formula is ZLEMA = EMA(close + (close - close[lag]), n), where lag is (n - 1) / 2. On a perfectly straight line its lag really is exactly zero, but only when the period is odd.

Three indicators get searched for under this name: the ZLEMA, the Jurik moving average and the MESA adaptive moving average. The ZLEMA reaches zero lag on a straight line, at periods we can name. The Jurik has no published formula, and the copy most people actually run removes about a third of the lag of a plain EMA. The MESA is published on a reference site in a form that cannot be run from what the page gives you.

What is a zero lag moving average?

A moving average built so that on a steadily rising or falling price it tracks the current price instead of a price from some bars back.

A plain exponential moving average cannot do that, and the reason is also the fix. The user42 chart manual puts it in one sentence: "A plain EMA applied to straight line points ends up always being the close at (N-1)/2 days ago". If you know how far behind the average sits, you can add that distance back on before you average.

What is the zero lag moving average formula?

ZLEMA = EMA( close + (close - close[lag]), n )

where  lag = (n - 1) / 2

Take today's close, add the change over the last "lag" bars, and feed that adjusted price into an ordinary EMA with the usual smoothing factor of 2 / (n + 1).

Two wordings look different and are the same arithmetic. The user42 manual and Tulip Indicators write the adjusted price as close + (close - close[lag]); VectorTA and TMGM write it as twice the price minus the price from lag bars ago. Those multiply out to the same number, and TMGM prints both forms next to each other.

Tulip Indicators gives the recursive form, with a = 2/(n+1) and each new value as (1 - a) times the previous value plus a times the adjusted price. Its references section cites the original article: "Stocks & Commodities V. 28:11 (30-35): Zero Lag (Well, Almost) by John Ehlers and Ric Way".

TMGM dates it and names the authors: John Ehlers and Ric Way, 2001, with Ehlers writing it up in his 2001 book Rocket Science for Traders.

What do you do when the lag is not a whole number?

For an even period, (n - 1) / 2 lands on a half, and the published instructions split three ways.

VectorTA floors it. Its formula marks the floor brackets on the lag, and its stated default period is 14. Its prose above the formula describes the lag more loosely as "half the period length", which is not quite what its own formula says.

StockGro rounds it up, worked at a 20-period setting: "Lag = (20-1)/2 = 9.5" and then "We will round up this figure and take the price from 10 periods ago."

TMGM names the fork and declines to pick: "A 20 period gives 9.5, and platforms round that differently, some down to 9 and some up to 10. So the same setting can show slightly different values on different charts." It then publishes a table with a column headed "Whole Number Needed?", marking period 9 and period 21 as No, and periods 20, 50 and 200 as Yes with both roundings named.

Most of the other pages give the lag as (n - 1) / 2 and never mention what to do when it lands on a half. So the fork is named in one place and left open in the original formula. None of them puts a size on it, or notices that the two choices differ in direction and not only in amount.

Which of these three does ChartLabs have?

All three. In the chart's Indicators menu, open the Standard list and look under the Moving Averages heading for Zero Lag Exponential Moving Average, Jurik Moving Average and MESA Adaptive Moving Average. Each of them draws on the price pane, over the candles. The Jurik arrives at Period 10, Phase 0, Power 0.45 and Source Close, and the MESA at Fast Limit 0.5, Slow Limit 0.05 and Source Close, drawing MAMA and FAMA as two lines; both are the versions discussed further down.

Our Zero Lag Exponential Moving Average has two settings, Length at 30 and Source at the close. On the fork above it takes the first side: ours floors the lag, so at the default length of 30 the lag is 14 bars rather than 14.5. That puts it half a bar behind price on the ramp measured below. Set an odd length and the question disappears, because there is no setting that switches the rounding.

Does the zero lag moving average actually have zero lag?

On a perfectly straight ramp, yes, exactly, and only at odd periods. On anything else, no.

Our ramp test: price rises 0.1 a bar, and the lag is how far behind the current price the line sits, read in bars.

nplain EMA lagZLEMA, lag flooredZLEMA, lag rounded up
52.00000.0000 (lag 2)0.0000 (lag 2)
94.00000.0000 (lag 4)0.0000 (lag 4)
104.5000+0.5000 (lag 4)-0.5000 (lag 5)
146.5000+0.5000 (lag 6)-0.5000 (lag 7)
157.00000.0000 (lag 7)0.0000 (lag 7)
209.5000+0.5000 (lag 9)-0.5000 (lag 10)
2110.00000.0000 (lag 10)0.0000 (lag 10)
5527.00000.0000 (lag 27)0.0000 (lag 27)

At an odd period the two published instructions agree, because (n - 1) / 2 is already whole, and the lag is exactly zero. At an even period they disagree, and they disagree in sign: floored, the line still lags by half a bar; rounded up, it runs half a bar ahead of price. A line that leads price is no longer an average of anything, and no source mentions that this is what one of the two readings does.

The straight line is a special case, and user42 says so on the same page that explains the lag: "On non straight line sequences the lag is not a simple (N-1)/2, but will vary according to shape, period of cyclical components, etc." A ramp is the one shape where "zero lag" has an exact meaning, which is why we use it. It is not a claim about your chart.

TMGM's own FAQ says: "the ZLEMA tries to eliminate lag in traditional moving averages, but it does not remove it completely. The ZLEMA is still built from past closing prices, and the EMA smoothing step still averages those prices over the chosen period, so a delay remains. That delay is shorter than an EMA's delay with the same period, but it is not zero." Its reading of the name follows from that: the zero lag part is what the indicator is called, and the line still turns only after price has begun to move.

Does the rounding choice matter on real bars?

Only at even periods, and there it matters on every single bar.

Our figures, on 7,092 EUR/USD daily bars from 2004-01-01 to 2026-08-31, counting from the point both lines are fully warmed up:

nlag flooredlag rounded upbars where the lines differmean gaplargest gapdays the direction differs
9440 of 7,0790.000.000
10457,077 of 7,07714.69 pips191.50 pips749 of 7,076
14677,071 of 7,07112.42 pips156.98 pips576 of 7,070
15770 of 7,0700.000.000
209107,062 of 7,06210.41 pips122.76 pips478 of 7,061
2110100 of 7,0610.000.000
5024257,017 of 7,0176.65 pips55.32 pips351 of 7,016
5527270 of 7,0100.000.000

On the index the same test gives mean gaps from 14.56 to 33.28 points and a largest gap of 421.89 points.

TMGM called this "slightly different values on different charts". At a 10-period setting it is a mean of 14.69 pips and a disagreement about the line's direction on 749 days out of 7,076.

Pick an odd period and the question cannot arise. TMGM's table shows that pattern in its own rows, with 9 and 21 marked No and 20, 50 and 200 marked Yes. It never states the rule in words.

What is the Jurik moving average formula?

There is no published formula. Anything presented as the JMA formula is either a reconstruction or something else wearing the name.

StockGro states the position three times on one page: "the exact formula is not open-source and is only available through licensed Jurik Research tools", "The exact formula is not public, but the results are clear when viewed on a chart", and in its FAQ, "The exact formula for the Jurik Moving Average is proprietary and not publicly available". It names Phase and Power as the two settings.

The implementation most people run is jma() in the pandas_ta library. It takes a close series and nothing else, no volume. Its defaults are a length of 7 and a phase of 0, with phase accepted from -100 to 100. Its own docstring claims the JMA "has extremely low lag, is very smooth and is responsive to market gaps", and its listed sources are a PDF attachment on an mql5 forum and a ProRealCode indicator page, not Jurik Research.

IndicatorChart contradicts that clone on a basic point. It says the JMA "is calculated using a proprietary formula that includes both price and volume data", while the public clone takes a single close series and never touches volume. Jurik's own implementation is not published, so the contradiction stands unresolved.

The same page then offers "two ways to calculate a Jurik moving average": a simple moving average and an exponential one. Neither is the JMA, and the page had called the formula proprietary a few paragraphs earlier. It also carries unrelated search phrases spliced into the middle of its sentences.

How much lag does the public Jurik clone actually remove?

Exactly 32.5%, at every length we tested, and never all of it.

Our figures, same ramp, running the pandas_ta implementation:

lengthJMA clone lagplain EMA of the same lengthreduction
72.0250 bars3.000032.5%
144.3875 bars6.500032.5%
216.7500 bars10.000032.5%
5016.5375 bars24.500032.5%

The clone's lag is a fixed proportion of the EMA's, so it does not improve as you lengthen the period. What its own docstring calls "extremely low lag" is a one-third reduction, while a ZLEMA at an odd period removes all of it on the same test.

That measures the public clone, not Mark Jurik's indicator, whose formula is not published. It is also not the Jurik Moving Average in ChartLabs, which follows a different open reconstruction, mihakralj's MIT-licensed script, with its defaults of Period 10, Phase 0 and Power 0.45. The ramp figures above are for the pandas_ta clone only.

The clone's source labels its own second stage "one more prelimimary smoothing by Kalman filter", spelling and all. What a Kalman filter actually is has its own guide.

What is the MESA adaptive moving average (MAMA and FAMA)?

An EMA whose smoothing factor is reset each bar from a measured cycle phase, plus a second slower line built from half that factor.

The open-source TA-Lib library's reference page describes it as "an adaptive EMA whose smoothing factor is driven by the dominant-cycle phase rate measured with a Hilbert transform. Emits two lines, MAMA and its slower follower FAMA". Its published pieces are:

deltaPhase = max(1, prevPhase - phase)
alpha      = max(fastLimit/deltaPhase, slowLimit) if deltaPhase > 1 else fastLimit
MAMA       = alpha*price + (1-alpha)*MAMA_prev
FAMA       = (alpha/2)*MAMA + (1-alpha/2)*FAMA_prev

Published defaults are a fast limit of 0.5 and a slow limit of 0.05, each accepting values from 0.01 to 0.99. The page references Ehlers, Rocket Science for Traders.

On that page the phase comes from atan(Q1/I1), and the page never defines I1 or Q1, so the formula as published cannot be run, and we publish no numbers for it. A reader who wants the full derivation has to go to the book the page cites. The MESA Adaptive Moving Average in ChartLabs computes the full Hilbert cycle that the page leaves out, draws both MAMA and FAMA, and uses the same defaults, Fast Limit 0.5 and Slow Limit 0.05.

That same reference ends its summary with a trade instruction, that MAMA crossing above FAMA is bullish and crossing below is bearish, printed in a library's reference page. We endorse neither direction.

What does any of this cost?

The same thing the whole family costs: the line stops being bounded by its own inputs.

Our step test, 400 bars at 100 then 400 at 101, so the highest price anywhere is exactly 101.000000:

linepeakovershoot, % of step
plain EMA, any period101.0000000.00%
ZLEMA n=14101.15249415.25%
ZLEMA n=20101.18747118.75%
ZLEMA n=55101.25082225.08%
JMA clone length=7101.0921299.21%
JMA clone length=21101.11588311.59%

On real bars, the ZLEMA printed above the highest close of its own window or below the lowest on 10.40% of 7,079 EUR/USD days at n=9, 2.73% at n=20 and 1.71% at n=55. On the index it is 11.67%, 5.10% and 3.89%, and at n=55 it is 152 days above and none below.

Three of the sources described this in words without putting a number on it. user42 explains the mechanism: the adjustment makes recent prices "over weight" and thus tracked closely, "and with negative weights on past terms". VectorTA warns under its own risk notes that the de-lagging "may overshoot compared to EMA". TMGM describes the consequence: "In a sideways market, the same adjustment can overshoot. A small move gets doubled, so when price turns back, the ZLEMA flips direction too. That overshoot is where the ZLEMA's whipsaws come from."

So which of these has the least lag?

On a straight-line test, in order:

linelag on a straight rampwhat we measured it from
ZLEMA at an odd period0.0000 barsthe published formula, both roundings agreeing
ZLEMA at an even period0.5 bars behind, or 0.5 aheadthe two published roundings
public Jurik clone32.5% of the matching EMA's lagthe pandas_ta source
MESA adaptive (MAMA)not measuredits published formula cannot be run as printed
plain EMA(n - 1) / 2 barsthe baseline

That is a ranking on one test, not a recommendation, and the least lag is not the same as the most useful. The overshoot figures run in the opposite order.

How do you test this yourself?

Feed the indicator a straight line and read off where the line sits against the last price. It takes about a minute and it settles the lag question for whatever you are running.

  1. Build a series that rises by a fixed amount every bar. Plot the indicator on it.
  2. Read the gap between the last price and the line, and divide by the step. That is your lag in bars.
  3. Then the step test: flat, then a jump, then flat. Note the highest value the line reaches against the highest price in the series. That is your overshoot.
  4. Only then go to real bars, and step forward one bar at a time so you cannot see what came next.
  5. If your period is even, run it twice with the lag floored and rounded up, and count the days the two disagree about direction.

All three lines are built into ChartLabs, in the place named near the top. The ramp of step 1 and the rounded-up version for step 5 still need your own Pine Script, in the built-in editor, where the Pine Scripts tab has two examples to start from. Every moving average gets its own colour and line style, so you can edit one instance without changing the others. Moving Average and Exponential Moving Average sit under the same heading in the Standard list, which gives you the baseline to measure against.

Step 4 is manual backtesting. For the full process see our beginner's guide to backtesting a strategy, and for pair-specific behaviour, forex backtesting.

What these numbers do not tell you

No win rate, no success rate, no accuracy figure for any of the three. Nothing we could read measures them, and neither have we.

The Hull moving average has its own construction, its own fraction problem and its own settings question. So do the DEMA and TEMA, and the Kalman filter.

Next step

The ramp test takes a minute and tells you what your platform's version of these lines actually does. Start a free trial of ChartLabs and run it on your own charts.

Related Topics

zero-lag-moving-averagezlemajurik-moving-averagemesa-adaptive-moving-averagemoving-averagesindicator-formula