Ehlers. The CG Oscillator
Ehlers. The CG Oscillator
By John Ehlers INTRODUCTION This article describes a new oscillator that is unique because it is both smoothed and has essentially zero lag. The smoothing enables clear identification of turning points and the zero lag aspect enables action to be taken early in the move. This oscillator is the serendipitous result of my research into adaptive filters. While the filters have not yet produced the result I seek, this oscillator has substantial advantages over conventional oscillators used in technical analysis. The !" in the name of the oscillator stands for the enter of !ravity of the prices over the window of observation. The enter of !ravity # !$ of a physical ob%ect is its balance point. &or e'ample, if you balance a () inch ruler on your finger, the ! will be at its * inch point. If you change the weight distribution of the ruler by putting a paper clip on one end, then the balance point #e.g. the !$ shifts toward the paper clip. +oving from the physical world to the trading world, we can substitute the prices over our window of observation for the units of weight along the ruler. With this analogy, we see that the ! of the window moves to the right when prices increase sharply. orrespondingly, the ! of the window moves to the left when prices decrease. COMPUTING THE CG The idea of computing the enter of !ravity arose from observing how the lag of various &I, #&inite Impulse ,esponse$ filters vary according to the relative amplitude of the filter coefficients. - .imple +oving -verage #.+-$ is a &I, filter where all the filter coefficients have the same value #usually unity$. -s a result, the ! of the .+- is e'actly in the center of the filter. - Weighted +oving -verage #W+-$ is an &I, filter where the most recent price is weighted by the length of the filter, the ne't most recent price is weighted by the length of the filter less one, and so on. The weighting terms are the filter coefficients. The filter coefficients of a W+- describe the outline of a triangle. It is well known that the ! of a triangle is located at one third the length of the base of the triangle. In other words, the ! of the W+- has shifted to the right relative to the /! of an .+- of equal length, resulting in less lag. In all cases of &I, filters the sum of the product of the coefficients and prices must be divided by the sum of the coefficients so that the scale of the original prices is retained.
The most general &I, filter is the 0hlers &ilter() , which can be written as1
Ehlers Filt =
i= 0
ci * Pr ice i
i= 0
ci
The coefficients of the 0hlers &ilter can be almost any measure of variability. I have looked at momentum, signal to noise ratio, volatility, and even .tochastics and ,.I values as filter coefficients. 2ne of the most adaptive set of coefficients arose from video edge detection filters, and was the sum of the square of the differences of each price to each previous price. In any event, the result of using different filter coefficients is to make the filter adaptive by moving the ! of the coefficients. While I was debugging the code of an adaptive &I, filter I noticed that the !, itself, moved in e'act opposition to the price swings. The ! moves to the right when prices go up and moves to the left when prices go down. +easured as the distance from the most recent price, the ! decreased when prices rose and increased when they fell. -ll I had to do was to invert the sign of the ! to get a smoothed oscillator that was both in phase with the price swings and had essentially zero lag. The ! is computed in much the same way as we computed the 0hlers &ilter. The position of the balance point is the summation of the product of position within the observation window times the price at that position divided by the summation of prices across the window. The mathematical e'pression for this calculation is1 CG =
i= 0
( xi + 1) * Pr icei
i= 0
Pr icei
In this e'pression we added one to the position count because we start our count with the most recent price at zero, and multiplying the most recent price by the position count would remove it from the computation. The 0asy3anguage code to compute the ! 2scillator is given in &igure (.
( )
4ohn 0hlers, 5onlinear 0hlers &ilters", .tocks 6 ommodities, -pr )77(, page )8 4ohn 0hlers, ,ocket .cience for Traders", 4ohn Wiley 6 .ons, 5ew 9ork, hapter (7
Inputs1 ?ars1
Figure ! Easy "anguage Co#e to Co$%ute the CG Oscillator :rice##;<3$=)$, 3ength#(7$> count#7$, 5um#7$, /enom#7$, !#7$>
5um @ 7> /enom @ 7> &or count @ 7 to 3ength A ( begin 5um @ 5um < #( < count$B#:riceCcountD$> /enom @ /enom < #:riceCcountD$> 0nd> If /enom EF 7 then ! @ A5um=/enom> :lot(# !, G !G$> :lot)# !C(D, G !(G$> In 0asy3anguage, the notation :riceC5D means the price 5" bars ago. Thus :riceC7D is the price for the current bar. ounting for the location is backwards from the current bar. In the code the summation is accomplished by recursion, where the count is varied from the current bar to the length of the observation window. The numerator is the sum of the product of the bar position and the price, and the numerator is the sum of the prices. Then, the ! is %ust the negative ratio of the numerator to the denominator. .ince the ! is smoothed, an effective crossover signal is produced simply by delaying the ! by one bar. -n e'ample of the ! 2scillator is shown in &igure ). In this case, I selected the length to be a (7 bar observation window. It is clear that every ma%or price turning point is identified by the ! 2scillator and the crossovers formed by its trigger with zero lag. .ince the ! 2scillator is filtered and smoothed, whipsaws of the crossovers are minimized. The appearance of the ! 2scillator varies with the selection of the observation window length. Ideally, the selected length should be half the dominant cycle length because half the dominant cycle fully captures the entire cyclic move in one direction. If the length is too long, the ! 2scillator is desensitized. &or e'ample, if the window length is one full dominant cycle, half the data pulls the cg to the right and the other half the data pulls the cg to the left. -s a result, the cg stays in the middle of the window and no motion of the ! oscillator is observed. 2n the other hand, if the window length is too short you are missing the benefits of smoothing. -s a result of this case, the ! 2scillator contains higher frequency components and is a little too nervous for profitable trading.
Figure &! The CG Oscillator 'ccurately I#enti(ies Each Price Turning Point
John Ehlers is president of MESA Software and is a frequent contributor to Stocks & Commodities. He is a pioneer in introducing Ma imum Entrop! Spectral Anal!sis to technical traders through his MESA software. He is also a pioneer in introducing the Hilbert "ransform with application to a number of unique indicators. He ma! be reached at #$%&' ()(*)+,$- or .ia his websites www.mesasoftware.com or www.mesa* s!stems.com.