OPEN-SOURCE SCRIPT

Wavelet Transform Trend [QuantAlgo]

4 654
🟢 Overview

The Wavelet Transform Trend is a trend-following indicator built on multi-level undecimated Haar wavelet decomposition rather than moving averages or fixed volatility bands. It separates the price series into approximation components that carry structural trend and detail components that carry short-term noise, discards or shrinks the noise, then reconstructs a denoised wavelet path from what remains. That path is wrapped in an ATR confirmation band that price must close beyond before the trend state flips, helping traders separate genuine directional structure from local oscillation across every timeframe and market.
snapshot
🟢 How It Works

The core engine is a dilated à trous cascade. Each stage widens the Haar filter by a factor of two and splits the series into a coarser approximation and the detail band at that scale, with no downsampling, so the decomposition stays shift invariant and every bar receives a coefficient at every level:
Pine Script®

Wavelet Period sets how much history the trend component draws on, and Wavelet Levels determines how that span is divided across scales. The dilation schedule is derived from both, so the deepest approximation always spans the requested period. Reconstruction is exact by construction, meaning the deepest approximation plus every detail band returns the original source, so removing or shrinking detail is the only thing that changes the output. With Wavelet Approximation Only enabled the details are discarded outright. With it disabled, each band is soft thresholded against its own estimated noise magnitude, so the same setting behaves consistently on any instrument.

The resulting path is smooth but continuous, so direction comes from wrapping it in an ATR band and requiring a close through it. Each band only trails in the favorable direction and freezes otherwise:
Pine Script®

The result is a binary state that holds through pullbacks inside the band and flips only on a confirmed close beyond it. The entire engine runs on confirmed bar data, so the wavelet path, the bands, the trailing level, the trend state, and the alerts all hold their last closed-bar values and the indicator does not repaint.
snapshot
🟢 Signal Interpretation

▶ Bullish Trend (Green): When price closes above the upper confirmation band, the indicator enters bullish mode with green coloring applied across the trend line, glow, radial layering, wave trail, and optional bar and background coloring. The trailing level switches to the lower band and ratchets upward with the wavelet path, holding through pullbacks that fail to close beneath it.

▶ Bearish Trend (Red): When price closes below the lower confirmation band, the indicator enters bearish mode with red coloring across all visual elements. The trailing level switches to the upper band and only tracks lower from that point, requiring a close above it before the state can flip back.
snapshot
🟢 Features

▶ Preconfigured Presets: Three parameter sets cover different trading approaches. "Default" targets swing trading on 1-hour and daily charts. "Fast Response" shortens the span, reduces decomposition depth, and narrows the band for intraday charts where the indicator needs to adapt to shorter-duration moves. "Smooth Trend" extends the span, deepens the decomposition, and widens the band for position trading on daily and weekly timeframes, where the cost of a false flip is higher than the cost of a delayed one. Selecting a preset overrides the individual wavelet and ATR inputs.
snapshot
▶ Built-in Alerts: Three alert conditions cover all directional states. "Bullish Wavelet Trend" fires on the bar where the trend direction flips from bearish to bullish. "Bearish Wavelet Trend" fires on the bar where it flips from bullish to bearish. "Any Wavelet Trend Flip" combines both into a single condition for traders who want a unified notification regardless of direction.
snapshot
▶ Visual Customisation: Two display modes cover different reading styles. Line plots the confirmed trailing level with glow and optional radial layering, Wave instead builds a smoke-trail from copies of the wavelet path with configurable layers, span, and brightness. Six colour presets (Classic, Aqua, Cosmic, Cyber, Neon, and Custom) apply coordinated bullish and bearish schemes across the trend line, glow, radial layering, wave shades, and optional bar and background colouring. Bar colouring tints price candles with the active trend colour at a configurable transparency level, and background colouring extends the directional tint across the full chart pane.
snapshot

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.