Separate the filter recurrence from its adaptation rule
John Ehlers publishes the fixed filter in Time Warp: Without Space Travel, Figure 7. His presentation Building Trading Systems On NonLinear Filters, slides 19 and 20, supplies the error-based adaptive rule. The accessible paper and presentation are distinct sources; the public TradingView publication by everget helps identify the indicator family, but this example is an independent implementation of the equations.
- Brackets mean one bar ago. L1 uses the newly computed L0 and the previous L0 and L1. Replacing every term with a previous-bar value changes the filter.
- The median uses five successive normalized errors, each calculated against its own rolling range. Taking a median of five raw errors and normalizing once is a different algorithm.
- The source uses a 20-bar error range and the high-low midpoint as price. These are reference settings, not a measured optimum for every instrument.
| Stage | Equation on bar t |
|---|---|
| First stage | L0 = (1 − gamma) × P + gamma × L0[1] |
| Second stage | L1 = −gamma × L0 + L0[1] + gamma × L1[1] |
| Third stage | L2 = −gamma × L1 + L1[1] + gamma × L2[1] |
| Fourth stage | L3 = −gamma × L2 + L2[1] + gamma × L3[1] |
| Price-level output | F = (L0 + 2 × L1 + 2 × L2 + L3) / 6 |
| Tracking error | D = abs(P − F[1]); H = highest(D, N); B = lowest(D, N) |
| Adaptive coefficient when H > B | R = (D − B) / (H − B); alpha = median(R, 5); gamma = 1 − alpha |