by John F. Ehlers
Look at any price chart, and you'll find that markets move up and down even while in a trend . Removing
the trend can help identify short-term turning points. Frequent STOCKS & COMMODITIES contributor John
Ehlers presents different techniques for detrending prices and his optimized detrending method as well.
We want to detrend data because we want to remove the longer-term variations so short term turning
points are easier to discern, enabling us to better pinpoint the best entry and exit points for short-term
trades. Since the goal of detrending is separation of time variables, it is logical that we can optimize the
calculation for our approach to the market. Short-term and long-term variations are synonymous with
high frequency and low-frequency components, respectively. This is important because optimization is
accomplished using modem digital filter theory. Using filters, we can readily separate the desired
frequency components and discard the undesired frequency components. Short term and long term are
relative to trading style. A 26-week cycle used by a stock trader is long term for a commodity trader using
daily data, for example. Similarly, an intraday trader considers anything longer than several hours to be
long term. The optimization we derive considers daily data, but the principles can be expanded for any
Before we optimize detrending, let us review conventional detrending techniques for their comparative
strengths and weaknesses.
At least three different detrending techniques can be commonly found: First, calculating the best-fitting
straight line as the trendline and subtracting the trendline from the raw data; second, calculating a moving
average as a trendline and subtracting that trendline from the raw data; and third, taking the difference of
two data points separated in time.
The easiest way to calculate the best-fitting trendline is to draw a straight line between successive highest
highs or lowest lows and then translate this line to the center of the data spread. The best-fitting straight line can also be calculated by linear regression, often desirable because nearby successive maxima cannot
be clearly identified. But this calculation can have accuracy problems. The trendline of a perfect sine
wave taken over one full cycle is exactly horizontal because the sine wave has as many points above zero
as it does below zero. When we calculate the best-fitting straight line to a single sine wave cycle by linear
regression, we get the result as seen in Figure 1. We would get the correct result if we took the span
between successive peaks or valleys and would get the incorrect slope in the opposite direction if we took
the span over the cycle with a 180-degree phase shift (Figure 2).