Whittaker Envelope [LuxAlgo]The Whittaker Envelope indicator is a visualization tool that uses Asymmetric Least Squares (ALS) to create a smooth, non-linear envelope that adapts to price extremes and troughs.
This indicator is for visualization purposes only and should not be used for direct trading signals without confirmation.
It is important to note that this script is displayed retrospectively . Because it calculates the best fit over a fixed historical window (the last N bars) using an iterative optimization process, the entire shape of the envelope can change as new data arrives. This means the indicator repaints and should be used to analyze overall market structure and volatility rather than for real-time execution.
🔶 USAGE
The Whittaker Envelope provides a unique way to visualize the "breathing" of the market. By applying different asymmetry parameters, the indicator generates a lower boundary that seeks out price troughs and an upper boundary that seeks out price peaks.
🔹 Trend and Volatility Analysis
The area between the upper and lower bounds represents the smoothed price range. A widening envelope suggests increasing volatility, while a narrowing one indicates consolidation. The dashed midline acts as a smoothed average of these two extremes, providing a baseline for the current trend.
🔹 Extrapolation
The tool includes a linear extrapolation feature that projects the current trajectory of the envelope into the future. This can help users visualize the potential direction of the trend if the current momentum persists.
🔶 DETAILS
The script implements the Whittaker-Eilers smoothing algorithm, which balances two conflicting goals: fitting the data points closely and keeping the resulting curve smooth.
By using Asymmetric Least Squares (ALS), we assign different weights to prices depending on whether they are above or below the curve. For the upper band, we use a high asymmetry value ( p ) so the curve is "pushed" toward the peaks. For the lower band, a very low p value is used to "pull" the curve toward the troughs.
🔶 SETTINGS
Length : The number of recent bars included in the calculation window.
Lambda (λ) : The smoothing factor. Higher values result in a stiffer, straighter envelope, while lower values allow the bands to follow price more closely.
Lower Asymmetry (p) : Controls how the lower band reacts to prices. Typically set to a very low value (e.g., 0.001) to ensure it follows the bottom of the price action.
Upper Asymmetry (p) : Controls how the upper band reacts to prices. Typically set to a very high value (e.g., 0.999) to ensure it follows the top of the price action.
Iterations : The number of times the ALS algorithm runs to refine the fit. More iterations provide a more accurate envelope but require more computational power.
Extrapolation : The number of bars to project the current slope of the bands into the future.
Source : The price data used for the calculation (default is Close).
אינדיקטור Pine Script®






















