159 views

Original Title: Zero Lag

Uploaded by nanaa0

- The Macd Indicator Revisited by John F. Ehlers
- hilbert_transform
- Hilbert Sine Wave
- 2009 Traders Expo John Ehler
- Predictive Indicators for Effective Trading Strategies - John Ehlers - MESA Software/Stockspotter.com
- Breadth
- J. M. Hurst - The Profit Magic of Stock Transaction Timing
- Master of Science-Embedded Systems Design Syllabus
- MACD
- pan tompkins algorithm
- C Algorithms for Real-time DSP - EMBREE
- DSP Lab Manual.pdf
- What Are Basic Mt Forex Indicators
- 3F3 7 Implementation of Digital Filters
- 3F3 Digital Filters 2011
- DEWESoft_Math_Training_21.pdf
- lec07
- Stalin Matlab 2017
- MB 0024
- 15 Ways to Trade Moving Averages by m Elgyar

You are on page 1of 8

By

John Ehlers

No causal filter can ever predict the future. As a matter of fact, the laws of nature

demand that filters all must have lag. However, if we assume steady state conditions –

that is, no new disturbing events – there are techniques we can use to reduce the lag of

these filters to nearly zero. It turns out that such filters are useful for technical analysts

to smooth data, and perhaps create some fast-acting indicators. This is possible

because the steady state assumptions are almost satisfied in the short run. These

techniques are not applicable to longer moving averages because steady state

conditions do not continue over a long time span. There are superior techniques for

creating longer term averages, such as nonlinear filters1 or by removing undesired

cycling components from a composite price waveform.2

Engineers would describe the zero lag process as the placement of a zero in the filter

transfer response such that the rate change of phase at zero frequency is zero.

Traders, on the other hand, can easily understand the zero lag effect as a relationship

between the lag of a moving average and momentum. In Figure 1 the solid line

represents a steady state price movement and the dashed line represents a moving

average of the price lagging by N bars. The lag is the horizontal span. An N bar

momentum has the vertical span as shown. If we add the N bar momentum to the

moving average we exactly recreate the original price movement. Thus, the goal of

attaining a zero lag moving average can be realized with this approach.

Lag compensation can be applied to either FIR filters (like simple moving averages) or

to IIR filters (like exponential moving averages). I will apply the lag compensation

technique to both types of filters, but we must first review some filter theory. The data

1

John Ehlers, “Rocket Science for Traders”, John Wiley & Sons, Chapters 17 and 18

2

John Ehlers, “MESA and Trading Market Cycles Second Edition”, John Wiley & Sons, Chapter 9

we use in trading is sampled data. We only get the data once an hour, once a day,

once a week, etc. One of the theories of sampled data is that the highest frequency we

can analyze is at half the sampling frequency. If we are using daily bars, then the

shortest period (that is, the highest frequency) is a 2 bar cycle. This highest frequency

is called the Nyquist frequency. It is convenient to normalize all analysis to the Nyquist

frequency. So, a 2 bar cycle has a normalized frequency of 1, a 4 bar cycle has a

normalized frequency of 0.5, an 8 bar cycle has a normalized frequency of 0.2, and so

on. The generalized equation relating the normalized frequency to cycle period is

Freq = 2 / Period or, conversely, Period = 2 / Freq

An exponential moving average works by taking a fraction of the current price and

adding it to the quantity one minus the fraction times the previous filter output. The

equation for an exponential moving average is

Filt = *Price + (1-)*Filt[1]

Where is the fraction and [1] means that function one bar ago

Written this way, we are assured that the two coefficients sum to unity. The coefficient

sum to unity is mandatory if the filter is to converge. For example, assume the price has

been zero for a long time and then suddenly jumps to a value of 1. The filter output

after the jump at the its input will be on the first sample. On the next sample the filter

output will be + *(1-). Eventually the filter output will converge to be near unity.

The lag of an exponential moving average is

Lag = 1/ - 1 3

Suppose = 0.2. In this case, lag is 4 bars. The equation for the usual exponential

moving average (EMA) is

Filt = .2*Price + .8*Filt[1]

To obtain zero lag, we must add a 4 bar momentum to the input because the lag of the

original EMA is 4 bars. The equation then becomes

Filt = .2*(Price + (Price – Price[4])) + .8*Filt[1]

= .2*(2*Price – Price[4]) + .8*Filt[1]

Figure 2 shows the amplitude response of the original EMA as a function of frequency

and Figure 3 shows its lag as a function of frequency. Note that the greatest lag occurs

at zero frequency. Lag at frequencies where the output amplitude is attenuated is

unimportant because small amplitudes make little contribution to the output. By

contrast, Figure 4 shows the amplitude response of the IIR zero lag data smoother and

Figure 5 shows its lag as a function of frequency. The zero frequency lag has been

reduced to zero. The gain, or amplification of in-band frequencies is unavoidable. The

gain can be reduced, but only at the expense of adding lag again. The gain contributes

to overshoot at price turning points. We will show that this small increase in gain is

tolerable in practical usage.

3

John Ehlers, “MESA and Trading Market Cycles”, John Wiley & Sons, Chapter 4

Figure 2. EMA Amplitude Response, = 0.2

Figure 4. Zero Lag IIR Filter Amplitude Response, = 0.2

My favorite FIR filter is

Filt = (Price + 2*Price[1] + 3*Price[2] + 3*Price[3] + 2*Price[4] + Price[5])/12

It is my favorite because it exactly nulls out the 2 bar, 3 bar, and 4 bar cycle

components that are present in the input price. The amplitude response of this filter is

shown in Figure 6. An FIR filter is a linear phase filter and lag is defined as the rate

change of phase as a function of frequency. This means that FIR filters have the same

lag at all frequencies, and this lag is (N-1)/2 for an N element FIR filter. Since my

favorite filter has 6 elements, its lag is 2.5 bars.

My favorite filter is already 6 bars long, and we prefer not to extend its length by another

2.5 bars when we compute the momentum. So, we will do the equivalent by multiplying

a 1 bar momentum by 2.5. This is valid because we are assuming steady state

conditions. We perform the calculations to compute the filter coefficients as shown in

Table 1, which is equivalent to an Excel Spreadsheet. Column 1 list the coefficients of

my favorite filter. Column 2 are these same coefficients delayed by 1 bar. Column 3 is

the 1 bar momentum, obtained by subtracting Column 2 from Column 1 for rows that

contain coefficients in Column 2. Column 4 is Column 3 multiplied by 2.5. The final

filter coefficients are shown in Column 5 as the sum of the filter and the multiplied

momentum (Columns 1 and 4). Therefore, the equation for the zero lag FIR filter is

Filt = (Price + 4.5*Price[1] + 5.5*Price[2] + 3*Price[3] - .5*Price[4] – 1.5*Price[5]

– 2.5*Price[6])/9.5

The filter is devided by 9.5 to normalize its output amplitude to the sum of the

coefficients, providing zero gain at zero frequency.

Table 1. Computing Zero Lag FIR Filter Coefficients

Filt Filt Lagged Momentum 2.5*Momentum Zero Lag Filt

1 1

2 1 1 2.5 4.5

3 2 1 2.5 5.5

3 3 0 0 3

2 3 -1 -2.5 -.5

1 2 -1 -2.5 -1.5

1 -1 -2.5 -2.5

Several bad things happen to my favorite filter when we reduce its lag, as shown in

Figure 7. First, the notch rejection of the 2 bar, 3 bar, and 4 bar cycles disappears.

Second, the out of band attenuation is generally decreased. Third, there is a substantial

increase in inband gain. This gain contributes to overshoots in the transient areas. But

this is the price that must be paid to obtain zero lag. The lag response of the filter in

Figure 8 shows that we attained our goal of zero lag at zero frequency. The large lags

in the attenuation band of the filter are basically irrelevant because the amplitude of

these components are reduced.

Figure 7. Zero Lag FIR Filter Amplitude Response

The real question of which zero lag filter is best for traders can only be answered in a

comparison using real data.

Figure 9. Zero Lag IIR Filter is Preferred Because it gives less Transient

Overshoot

- The Macd Indicator Revisited by John F. EhlersUploaded bymuhkito
- hilbert_transformUploaded bygargrahul20004612
- Hilbert Sine WaveUploaded byagrid99
- 2009 Traders Expo John EhlerUploaded byMichael Spada
- Predictive Indicators for Effective Trading Strategies - John Ehlers - MESA Software/Stockspotter.comUploaded byInterconti Ltd.
- BreadthUploaded byemirav2
- J. M. Hurst - The Profit Magic of Stock Transaction TimingUploaded bywise_seer
- Master of Science-Embedded Systems Design SyllabusUploaded byShiv Ram Ch
- MACDUploaded byrahul dhawan
- pan tompkins algorithmUploaded byLeslie Wright
- C Algorithms for Real-time DSP - EMBREEUploaded byLuiz Carlos da Silva
- DSP Lab Manual.pdfUploaded byRavi Jaiswal
- What Are Basic Mt Forex IndicatorsUploaded byFrancis Ogene
- 3F3 7 Implementation of Digital FiltersUploaded bySarvender Singh
- 3F3 Digital Filters 2011Uploaded bySidharth Mahotra
- DEWESoft_Math_Training_21.pdfUploaded byUfuk Uzundağ
- lec07Uploaded byblablablou
- Stalin Matlab 2017Uploaded byAnonymous A4r48uVM
- MB 0024Uploaded byAmeer Abbas
- 15 Ways to Trade Moving Averages by m ElgyarUploaded byAnalisando a bolsa
- dsp 2 marksUploaded byKarthikeyan Tamilselvam
- Force Index -Stock Technical IndicatorUploaded byTony C.
- Sales Forecasting Practices of Egyptian Public Enterprises- SurveyUploaded bydocumentary123
- Implementation of High Speed FIR Filter Using SerialUploaded byshabbir470
- Important QuestionsUploaded byPriya
- ECE - DSP - Rec - QBUploaded byAshrafKhan
- DSP MANUAL 16-17.docxUploaded byChadalavada Mohansai Kumar
- dsp3Uploaded byJames Francis
- NI Tutorial 9700 EnUploaded byharivarahi
- 11-61-68Uploaded bylambanaveen

- Smart Lights.pdfUploaded bysatishkvr
- SI WH R500 EnglishUploaded byDinu Marian
- Www.sefindiaUploaded bySivaAgathamudi
- Frigidaire Refrigerator ManualUploaded byRay Ravel
- IMPROVING THE MF-TDMA SPECTRAL EFFICIENCY THROUGH SYMBOL SYNCHRONOUS OPERATIONUploaded byVinod Gowda
- PBQ-SF - Structure of the PBQ-SF- Smallest Space Analyses 2012Uploaded byDoniLeite
- (0048) POS USBN 2018-2019 Versi 29 Nov FinalUploaded bysupriyadi aris
- Commencal Techbook 2010 EnUploaded bytredd2
- Design 9Uploaded byemaster1
- Smart MaterialsUploaded byManjunath Keshav D M
- Atlas TiUploaded byDrEman Elsalhen
- Aero Town (Bare Chassis)Uploaded byPhilippine Bus Enthusiasts Society
- FPPresentation.pdfUploaded byudunge
- Engineering MechanicsUploaded byvidya_k_11
- 1 Argumentation & DebateUploaded byJobelle Montecillo
- 100 Autocad Tips You Should KnowUploaded byloopback127xyz
- STR-103-DETAILS OF LINTEL BEAM-1.pdfUploaded byUDay
- MM Syllabus BCom LLB.pdfUploaded byvinulal
- 5200043 2.1 RaySafe Xi Classic Specifications en WebUploaded byCat-Per
- Ernst Cassirer - The Philosophy of Symbolic Forms Vol. 1_ Language. 1-Yale University Press (1980).pdfUploaded byVíctor Iván González Guevara
- SIP Guide Annex 5C - WHY Diagram (12August2013)[1].docxUploaded byLauro Gacusana
- MEC442_KJM492 (9)Uploaded byafnanhanany
- A Few Remarks on Some Key Factors in Analysing Source Texts. a Response to Anna TrosborgUploaded byMatin
- safety-03-00013-v2 (1)Uploaded byAurelian Radu
- Chapter12.ans.docUploaded byBlasta45
- science a1b - stage 2 - 3 lessons markedUploaded byapi-354168340
- Tell Me About Yourself. - HR Interview Questions and AnswersUploaded byNikunj Savani
- Jyotish_Delayed Marriage of Girls_ KN.raoUploaded byVarun Kalra
- 4discourse Analysis VocabularyUploaded byDwi Anisa F
- senior seminar portfolio reflectionUploaded byapi-317889705