OPEN-SOURCE SCRIPT

Daubechies D4 Denoising [LB]

368
Concept
The Daubechies D4 Wavelet Denoising indicator applies a multi‑level discrete wavelet transform using the compactly supported Daubechies D4 wavelet (Ingrid Daubechies, 1992) combined with Donoho's universal threshold (Donoho & Johnstone, 1994). It separates price into approximation (trend) and detail (noise) coefficients, attenuates noise via soft thresholding, and reconstructs a denoised price curve that directly overlays the chart.

Mathematical Foundation
The Daubechies D4 wavelet is defined by four scaling coefficients h and four wavelet coefficients g, forming quadrature mirror filters that satisfy perfect reconstruction. At each level, the input array a is circularly convolved with h and g, then downsampled by two to produce the approximation a' and detail d' :

a'[k] = SUM_m h[m] * a[2k - m]
d'[k] = SUM_m g[m] * a[2k - m]

This process is iterated J times. The universal threshold lambda is estimated for each detail array independently using the median absolute deviation (MAD) of the coefficients :

sigma = MAD / 0.6745
lambda = sigma * sqrt(2 * log N)

Soft thresholding is then applied to each detail coefficient x :

threshold(x) = sign(x) * max(|x| - lambda, 0)

Finally, the denoised signal is reconstructed by upsampling, convolution with synthesis filters, and summation of approximation and detail contributions.

What Problem Does It Solve ?
Classical moving averages and low‑pass filters eliminate noise at the cost of significant lag and do not adapt to the local structure of the data. The Daubechies D4 wavelet denoising preserves sharp transitions (edges) while removing high‑frequency noise, offering a lag‑free, adaptive smoothing that respects the multi‑scale nature of price action.

How To Interpret
Denoised line above price – the smoothed trend is stronger than the current raw price; underlying momentum remains positive despite transient dips.
Denoised line below price – the smoothed trend is weaker; price is correcting within a larger structure.
Denoised line flattening or changing direction – a regime shift may be underway; the multi‑scale trend is losing or gaining momentum.

Parameters
Source – price field to denoise (default close).
Decomposition Levels – number of wavelet decomposition iterations. Higher levels remove lower‑frequency components, producing a smoother but more slowly reacting line.
Window Length (power of 2) – analysis window size. Must be a power of two for the dyadic decomposition; the indicator automatically adjusts to the largest valid power of two if an invalid value is entered.

Reference
Daubechies I., "Ten Lectures on Wavelets", Society for Industrial and Applied Mathematics, 1992.
Donoho D.L. & Johnstone I.M., "Ideal Spatial Adaptation by Wavelet Shrinkage", Biometrika, Vol. 81, No. 3, pp. 425‑455, 1994.

Отказ от ответственности

Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.