OPEN-SOURCE SCRIPT

Wavelet Trend Filter

202
What it is

A denoised price line whose smoothing is derived from measured noise, not a period you pick — plus the tool's signature number, the noise fraction (what share of the recent move is noise vs structure). Most published "wavelet denoising improves prediction" results denoise the whole series including future bars, which is lookahead-contaminated and impossible live. This tool refuses that: it runs a Haar wavelet transform over a trailing power-of-two window and keeps only the endpoint as today's value, fixed at close and never revised. Strictly causal, non-repainting, no forecast.

How it's built

The engine is a five-step Donoho-Johnstone wavelet shrinkage, run every bar over a trailing window (default 128 bars): a Haar DWT (shortest support, fewest boundary coefficients — the right choice for short causal series); noise scale σ = MAD(finest detail coefficients)/0.6745 (robust to outliers); the universal threshold λ = σ·√(2 ln n) with an optional multiplier; soft or hard shrinkage of the detail coefficients; and an inverse transform, keeping the endpoint. Optional symmetric reflection padding reduces edge distortion. Because the threshold self-scales from measured noise, a quiet tape is smoothed less and a noisy tape more — automatically, on any timeframe.

Derived reads: noise fraction = 1 − var(denoised)/var(raw) over the window (share the transform removed), ranked into a percentile; trend slope in noise-σ units; and a signal-to-noise strength = slope (σ) × structure share (1 − noise fraction), the single "is this trend real?" number.

How you read it — and the honest actionable signal

The noise fraction gates everything. A bold chop/structure ribbon along the bottom of the chart shows the whole regime spectrum (green = structure/low noise/trend trustworthy, red = chop/high noise/stand aside), and a ±1σ noise envelope around the denoised line makes the removed noise visible — so it's obviously not just a moving average.

The actionable markers are structure-gated: a green ▲ / red ▼ prints when the denoised slope turns up/down and the tape has structure (low noise); in chop the tool withholds and marks the turn with a small caution dot instead. A hysteresis on the structure state keeps the signals from re-firing as noise oscillates. This is not a blind crossover generator — it goes quiet exactly when the tape is too noisy to trust, which is when ordinary signals whipsaw. The panel's "Read" row states the current call in plain English ("up-trend · structure ✓", "chop — stand aside").

Exports & alerts

EXP_Denoised · EXP_NoiseSigma · EXP_NoiseFrac (0–1) · EXP_Slope (σ) · EXP_SNR (trend strength) · EXP_Stance (+1 up·structure / −1 down·structure / 0). Alerts: noise fraction entering top / bottom quartile (chop / structure) · denoised slope turning up / down · confirmed up-trend / down-trend with structure present.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.