OPEN-SOURCE SCRIPT

Ehlers Decycler (DECYCLER)

545
The Ehlers Decycler extracts the trend component from a price series by subtracting a 2-pole Butterworth high-pass filter from the source. Cycles shorter than the cutoff period are removed; everything longer passes through with near-zero phase lag. The result is a trend overlay that tracks price more closely than a comparable EMA during trends, with no smoothing window, no lag-versus-smoothness tradeoff, and exactly one parameter.

HISTORICAL CONTEXT

John Ehlers introduced the Decycler in "Decyclers" (Technical Analysis of Stocks & Commodities, September 2015), alongside its oscillator companion DECO. The underlying 2-pole Butterworth high-pass filter had appeared in Ehlers' earlier work (Cybernetic Analysis for Stocks and Futures, 2004), primarily for cycle measurement. The Decycler simply inverts the question: instead of isolating cycles, subtract them. What remains is trend.

The approach sidesteps the fundamental tension in trend-following design. Moving averages introduce lag proportional to their smoothing window. Adaptive averages reduce lag but add parameters and complexity. The Decycler reframes the problem as a frequency-domain operation: define a cutoff period, remove everything above it, keep everything below. The phase response of the complementary filter preserves the phase of passed frequencies — trend components below the cutoff experience near-zero lag by construction, not by approximation.

HOW IT WORKS

Stage 1 — 2-pole Butterworth high-pass filter
A single coefficient α is derived from the cutoff period P using the Butterworth −3 dB design point (the 0.707 = 1/√2 factor places the half-power point at exactly period P):

ω = 0.707 × 2π / P
α = (cos(ω) + sin(ω) − 1) / cos(ω)

Three recurrence coefficients are computed once at construction from α:

a₁ = (1 − α/2)² ← input gain
b₁ = 2(1 − α) ← first feedback
c₁ = −(1 − α)² ← second feedback

The HP recurrence runs each bar:

HP[t] = a₁ × (x[t] − 2x[t−1] + x[t−2]) + b₁ × HP[t−1] + c₁ × HP[t−2]

The second-difference term (x[t] − 2x[t−1] + x[t−2]) is a discrete second derivative — it rejects DC and linear trends while passing oscillatory content, which the HP feedback then sharpens into a proper bandpass edge.

Stage 2 — Complementary subtraction
The Decycler is one line:

Decycler[t] = x[t] − HP[t]

This guarantees that Decycler + HP = price at every bar. No signal energy is created or destroyed. The trend and cycle components sum exactly to the original series.

Frequency response
- Periods longer than the cutoff: unity gain, near-zero phase shift.
- Periods shorter than the cutoff: attenuated at −12 dB/octave (2-pole rolloff).
- At exactly period P: −3 dB (≈29% amplitude reduction).


INPUTS & PARAMETERS

- Source — Input series. Default: close.
- Period — Cutoff period in bars. Cycles shorter than this are removed. Default: 60.

Period selection
- 20–30: Responsive trend line, tracks swings. Short-term trading on daily bars.
- 40–80: Balanced separation. Default of 60 works well for daily timeframes.
- 100–200: Heavy smoothing, reveals major trend direction only. Position trading and regime detection.

Ensure the dataset has at least 2 × period bars for meaningful trend extraction. On a 100-bar chart, a period of 200 removes almost nothing — the cutoff falls below the Nyquist limit of the data.

HOW TO USE

Trend direction
- Price above Decycler → bullish. Price below → bearish.
- Slope of Decycler indicates trend momentum. Flattening slope → potential exhaustion or transition.

Trend vs. cycle regime
- Decycler hugging price closely → trending: the dominant cycle is shorter than the cutoff and is being removed, leaving clean trend.
- Decycler oscillating with small amplitude → ranging: price is spending time in both directions relative to the trend line.

Multi-period overlay
- Two Decycler instances at different periods (e.g., 30 and 120) reveal short-term and long-term trend simultaneously. Their relationship is interpretable in frequency terms — the gap between them is a specific cycle band.

Cycle complement
- The HP component (price − Decycler) isolates the cycle content. Plot it separately as a zero-mean oscillator to see what the Decycler is removing. If the cycle is large relative to trend, reduce position size.

This is not a moving average
- The Decycler does not compute a weighted sum of past prices. During strong trends it tracks price more closely than a same-period EMA. During ranging conditions it can exhibit small oscillations that a moving average would suppress. Factor this into signal logic.

LIMITATIONS

- Period too short: A cutoff of 10 on daily bars removes only cycles shorter than 10 days — nearly everything passes through and the Decycler approximates raw price. Meaningful separation requires the cutoff period to exceed the dominant cycle in the data.
- Not DECO: The Decycler is a lowpass trend overlay (price − HP). The Decycler Oscillator (DECO) is HP_long − HP_short — a bandpass oscillator that crosses zero. They share the same filter core but produce fundamentally different outputs. Using one where the other is needed produces incorrect results silently.
- Warmup: The HP recurrence requires two prior source values and two prior HP values. For the first two bars, HP = 0 and Decycler = raw price. IsHot = true after period bars; signals before that point are unreliable.
- IIR drift: Feedback terms accumulate floating-point error over very long series (> 10,000 bars). For typical trading horizons (< 5,000 bars), drift stays below 1e−10 and is inconsequential.
- No external validation baseline: TA-Lib, Skender, Tulip, and OoplesFinance do not implement the Ehlers Decycler. Validation is against the Pine reference implementation and internal streaming/batch/span consistency.

REFERENCES

- Ehlers, J. F. (2015). "Decyclers." Technical Analysis of Stocks & Commodities, September 2015.

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.