OPEN-SOURCE SCRIPT
Isotonic Regression [LuxAlgo]

The Isotonic Regression indicator provides a monotonic fit to price data, ensuring the resulting line is either non-decreasing or non-increasing over a specified lookback period. This tool is particularly useful for identifying underlying trends and significant price plateaus without the lagging or "overshooting" common in standard moving averages or linear regressions.
🔶 USAGE
Isotonic regression is used to find the best-fitting line to a set of data points under the constraint that the line must move in a specific direction (always up or always down). This creates a "staircase" effect where the model alternates between trending segments and flat plateaus.
🔹 Direction Modes
The indicator offers three ways to determine the fit direction:
🔹 Flat Period Extensions
One of the most powerful features of isotonic regression is the identification of "blocks" or price levels where the trend pauses. When the duration of such a plateau exceeds the Flat Period Threshold, the indicator extends a dashed horizontal line to the current bar, highlighting potential support or resistance levels derived from the regression model.
🔶 DETAILS
The script implements the Pool Adjacent Violators Algorithm (PAVA), which is the standard method for computing isotonic regression.
The algorithm works by partitioning the data into "blocks." If a subsequent data point violates the monotonicity constraint (e.g., price drops in a "non-decreasing" fit), the algorithm pools the current block with the previous one and calculates a weighted average. This process repeats until the entire sequence is monotonic.
For performance efficiency, the indicator utilizes thePine Script® function to render the regression line as a single continuous object rather than hundreds of individual line segments.
🔶 SETTINGS
🔹 Style
Note: This indicator calculates its values based on a historical lookback window, which means the regression line will repaint as new bars are added and the window shifts.
🔶 USAGE
Isotonic regression is used to find the best-fitting line to a set of data points under the constraint that the line must move in a specific direction (always up or always down). This creates a "staircase" effect where the model alternates between trending segments and flat plateaus.
🔹 Direction Modes
The indicator offers three ways to determine the fit direction:
- Auto: Automatically detects the trend by comparing the start and end prices of the lookback period. If the end price is higher, it fits a non-decreasing line; otherwise, it fits a non-increasing line.
- Non-Decreasing: Forces the fit to only move upwards or stay flat, ideal for analyzing bullish structures.
- Non-Increasing: Forces the fit to only move downwards or stay flat, ideal for analyzing bearish structures.
🔹 Flat Period Extensions
One of the most powerful features of isotonic regression is the identification of "blocks" or price levels where the trend pauses. When the duration of such a plateau exceeds the Flat Period Threshold, the indicator extends a dashed horizontal line to the current bar, highlighting potential support or resistance levels derived from the regression model.
🔶 DETAILS
The script implements the Pool Adjacent Violators Algorithm (PAVA), which is the standard method for computing isotonic regression.
The algorithm works by partitioning the data into "blocks." If a subsequent data point violates the monotonicity constraint (e.g., price drops in a "non-decreasing" fit), the algorithm pools the current block with the previous one and calculates a weighted average. This process repeats until the entire sequence is monotonic.
For performance efficiency, the indicator utilizes the
🔶 SETTINGS
- Lookback Length: The number of bars used to calculate the isotonic fit.
- Source: The price data used for the calculation (default is Close).
- Direction: Sets the monotonicity constraint (Auto, Non-Decreasing, or Non-Increasing).
- Flat Period Threshold: The minimum number of bars a price plateau must last to be highlighted with an extension line.
🔹 Style
- Fit Bullish/Bearish: Colors for the regression line based on the detected trend.
- Fit Style/Width: Controls the visual representation (Solid, Dashed, Dotted) and thickness of the main regression line.
- Ext Bullish/Bearish: Colors for the flat period extension levels.
- Ext Style/Width: Controls the visual representation and thickness of the plateau extensions.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
All content & scripts provided by LuxAlgo are for educational purposes only and are not financial advice.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
All content & scripts provided by LuxAlgo are for educational purposes only and are not financial advice.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.