Daily Polynomial Regressions [LuxAlgo]The Daily Polynomial Regressions indicator uses matrix calculations to solve polynomial regression (degrees 1-4) on a daily basis, providing a dynamic visualization of intraday trends and price distribution.
By fitting a curved line to price action throughout the trading session, it helps traders identify the underlying momentum and strength of the daily trend.
The fit for the current day may be subject to repainting
🔶 USAGE
The indicator highlights each trading day with a dynamic box that expands as the daily high and low are updated. Inside this box, a polynomial regression curve is plotted using a polyline to represent the best-fit path of price action for that specific day.
The tool is particularly useful for identifying:
Intraday Trend Direction: The background and curve color change based on whether the current regression endpoint is higher (bullish) or lower (bearish) than its daily starting point.
Trend Strength: A higher R² value indicates that the price action is following the regression curve more closely, suggesting a more "orderly" or predictable trend.
Mean Reversion: The regression curve acts as a dynamic moving average that adapts to the specific curvature of the day's price movement, highlighting potential overextensions.
🔶 DETAILS
🔹 Polynomial Degrees
The indicator allows users to select between different regression complexities:
Degree 1 (Linear): Fits a straight line. Best for identifying simple linear trends.
Degree 2 (Quadratic): Fits a simple curve (parabola). Useful for identifying trend exhaustion or rounding tops/bottoms.
Degree 3 (Cubic) & 4 (Quartic): Provides a highly flexible curve that can account for multiple shifts in momentum within a single day.
🔹 Matrix Calculations
Unlike standard moving averages, this script solves the Normal Equation (X'X)B = X'Y using matrix inversion to find the coefficients for the selected polynomial degree. All accumulators reset at the start of each new day to ensure the analysis remains strictly intraday.
🔹 R-Squared (R²)
The R² statistic is calculated as 1 - (SSres / SStot). It represents the proportion of variance for the price that's explained by the polynomial model. A value of 1.0 would mean the price is perfectly following the curve.
🔶 SETTINGS
Polynomial Degree: Determines the complexity of the regression curve (1: Linear, 2: Quadratic, 3: Cubic, 4: Quartic).
Show Median Line: Toggles the visibility of a dashed line representing the midpoint (HL2) of the daily high-low range.
Show R² Label: Displays the R-squared statistic at the top of the daily box to indicate how well the curve fits the price data.
Bullish Color: The color used for the curve and box background when the trend is positive.
Bearish Color: The color used for the curve and box background when the trend is negative.
Fill Transparency: Adjusts the opacity of the daily background highlighting.
Pine Script® 인디케이터






















