OPEN-SOURCE SCRIPT

Trend filter v2 [Jamallo]

4 570
Intro
Trend Filter v2 is the evolution of the original Trend Filter, replacing the Kalman Filter baseline and WMA-scaled bands with a kernel-smoothed Vervoort Stop and percentile-ranked deviation bands. It also draws conceptual lineage from the ENW Kernel Bands indicator, inheriting the composite kernel and dual-Vervoort architecture — but rethinking both what the kernel is applied to and how bands are sized.

Breakdown

A Line — Vervoort Stop
A classic trailing stop built on Heikin Ashi smoothed price and ATR. Color-coded by a trend state machine: bullish when price is above a rising A line, bearish when below a falling one, neutral otherwise. This is the signal line.

K Line — Kernel-Smoothed Vervoort Stop
Unlike ENW where the composite kernel is applied directly to raw price, v2 feeds a second Vervoort Stop output into the kernel. This means the K line is trend-filtered before smoothing even begins, producing a slower, more structurally stable baseline that is less reactive to noise.

Signal Line — Independent Vervoort Stop
A third Vervoort Stop with its own ATR settings, used as an additional trend reference.

Percentile Bands
The key structural departure from both v1 and ENW. Instead of scaling bands by smoothed volatility × a fixed multiplier, v2 ranks upside and downside deviations from K separately using `percentile_nearest_rank` over a configurable lookback.

END

v2 replaces the Kalman with a kernel-smoothed Vervoort Stop and swaps fixed-deviation bands for percentile-ranked asymmetric bands — a fundamental rethink of both the baseline and the band sizing at every level.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.