OPEN-SOURCE SCRIPT

Spline Quantile Regression Channel [LuxAlgo]

32 126
The Spline Quantile Regression Channel indicator implements an advanced non-linear regression model to fit a flexible, multi-level channel over recent price action. Unlike standard linear regression which identifies the mean trend, this tool fits specific price percentiles (quantiles) using cubic splines, providing robust support and resistance zones that adapt to market volatility and non-linear structures.

🔶 USAGE

The indicator is designed to provide a sophisticated view of the current trend and its extremes. By fitting cubic splines to specific quantiles, the script offers a "bendable" channel that can follow complex price movements more accurately than traditional straight-line regressions.

🔹 Trend Identification
The median line (default 0.5 quantile) represents the central tendency of the price action. When the spline is sloping upward, it indicates a non-linear bullish regime; a downward slope indicates a bearish regime.

🔹 Support and Resistance
The upper and lower bands represent the specified extremes (e.g., the 90th and 10th percentiles). These act as dynamic boundaries:
  • Prices reaching the upper band often indicate overextended conditions within the current lookback period.
  • Prices reaching the lower band suggest the asset is trading at the lower end of its recent distribution.


🔹 Forecasting
The indicator projects the calculated spline into the future using a dashed line. This forecast is a mathematical extrapolation of the current non-linear trend, helping traders visualize where the price distribution is headed if the current momentum and curvature persist.

🔶 DETAILS

The script employs several advanced mathematical concepts to ensure accuracy and stability:

  • Cubic Spline Basis: The model uses a piecewise polynomial basis ($1, x, x^2, x^3$) combined with truncated power functions at "knots." This allows the curve to change its curvature locally, adapting to swings that a simple polynomial cannot capture.
  • Quantile Optimization: Instead of minimizing squared errors (OLS), the script uses an Iteratively Reweighted Least Squares (IRLS) solver to minimize the "check function." This allows the script to target specific percentiles of the price data.
  • Numerical Stability: To prevent matrix overflows common in high-degree polynomial calculations, the script standardizes price data (Z-score) and scales time coordinates between 0 and 1 before performing matrix inversion.


🔶 SETTINGS

🔹 Spline Configuration
  • Lookback Period: The number of historical bars used to fit the spline regression. Larger windows result in a more "macro" trend, while smaller windows react quickly to recent changes.
  • Internal Knots: Determines the "flexibility" of the spline. More knots allow the curve to follow price swings more tightly, while fewer knots yield a smoother, more rigid curve.


🔹 Optimization
  • IRLS Iterations: The number of optimization passes for the solver. Higher values improve the accuracy of the quantile fit, especially in volatile markets.
  • Forecast Length: The number of bars to project the calculated spline into the future.


🔹 Quantile Levels
  • Upper Quantile: The specific percentile for the upper band (e.g., 0.95 for the top 5%).
  • Median Quantile: The central percentile (typically 0.5 for the median).
  • Lower Quantile: The specific percentile for the lower band (e.g., 0.05 for the bottom 5%).


🔹 Visuals
  • Colors: Individual color settings for the upper, median, and lower bands.
  • Line Width: Controls the thickness of the polylines rendered on the chart.

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน