OPEN-SOURCE SCRIPT
Statistical Trend Forecast Pro

📈 OverviewStatistical Trend Forecast Pro
is an advanced predictive tool designed to project future price action based on rigorous statistical analysis. Unlike standard lagging indicators (like Moving Averages), this script calculates the exact trajectory of the current trend using Linear Regression (Least Squares Method) and projects a "Cone of Uncertainty" into the future.This tool answers three critical questions for any trader:What is the true direction (Slope) of the current trend?Where is the price statistically likely to go (Target)?When does a move become statistically extreme (Breakout/Reversal)?
🧠 Theoretical BackgroundThe core engine of this indicator uses Covariance to calculate the precise slope and intercept of the price relative to time.The Forecast Line: A projection of the regression line into the future.The Cone of Uncertainty: Financial markets follow a "Random Walk" component. This indicator models volatility dispersion using a square-root-of-time function ($\sqrt{t}$). This means the further we look into the future, the wider the channel becomes, reflecting the natural increase in uncertainty.
✨ Key FeaturesDual-Threshold System (Visual vs. Alerts):Visual Channel: Draw the cone at a standard level (e.g., 2.0 Sigma) to see the general context.Background Alerts: Set alerts at a higher threshold (e.g., 3.0 Sigma) to be notified only during extreme volatility events, keeping your chart clean but your surveillance tight.Smart Dashboard:A customizable table displays the exact Trend Slope, Target Price, and Volatility Range in real-time.Includes color-coding (Green/Red) to instantly identify trend direction.Advanced Alert Engine:Breakout: Triggered when price exits the statistical cone.Re-Entry (Mean Reversion): Triggered when price returns into the cone after an excursion.Trend Filtering: Option to ignore signals that go against the main slope.Polyline Rendering: Uses Pine Script v6 dynamic polylines for smooth, curved visualization of the uncertainty cone (no blocky steps).Source Flexibility: Supports hlc3 (Typical Price) or hl2 input sources to reduce noise from candle wicks.
📚 User Manual & StrategiesStrategy 1: The "Volatility Squeeze" BreakoutSetup: Look for the cone to become narrow (low historical volatility).Trigger: Price breaks out of the cone's upper or lower boundary with a steep slope.Confirmation: The Dashboard Slope turns bright Green (Bullish) or Red (Bearish).Logic: A breakout from a low-volatility statistical range often signals the start of a new impulsive trend.Strategy 2: Mean Reversion (The "Rubber Band")Setup: Price extends far beyond the cone (e.g., hitting the 3.0 Sigma invisible wall).Trigger: Use the "Re-Entry" Alert. Wait for the price to close back inside the cone.Target: The central dashed orange line (The Regression Mean).Logic: Prices rarely stay at 3+ standard deviations for long. A return to the mean is statistically probable.Strategy 3: Trend Following with ConfluenceSetup: Enable "Filter by Trend" in the settings.Action: Only take Long trades if the Forecast Slope is positive, or Short trades if negative. Use the central dashed line as a dynamic trailing stop or support level.
⚙️ Settings GuideLookback Length: The number of past bars used to calculate the trend. (Default: 30)Forecast Horizon: How many bars into the future to project. (Default: 20)Widening Factor: Controls how fast the cone opens up. Higher values = wider cone end (more uncertainty).Alert Trigger (Sigma): The multiplier for backend alerts. Set this higher than the "Visual Channel" to filter noise.Source Data: Recommended set to hlc3 to include wicks in the calculation, or close for standard analysis.
⚠️ Disclaimer:This tool provides statistical projections based on past data. It does not guarantee future performance. Use it as part of a comprehensive trading strategy with proper risk management.
is an advanced predictive tool designed to project future price action based on rigorous statistical analysis. Unlike standard lagging indicators (like Moving Averages), this script calculates the exact trajectory of the current trend using Linear Regression (Least Squares Method) and projects a "Cone of Uncertainty" into the future.This tool answers three critical questions for any trader:What is the true direction (Slope) of the current trend?Where is the price statistically likely to go (Target)?When does a move become statistically extreme (Breakout/Reversal)?
🧠 Theoretical BackgroundThe core engine of this indicator uses Covariance to calculate the precise slope and intercept of the price relative to time.The Forecast Line: A projection of the regression line into the future.The Cone of Uncertainty: Financial markets follow a "Random Walk" component. This indicator models volatility dispersion using a square-root-of-time function ($\sqrt{t}$). This means the further we look into the future, the wider the channel becomes, reflecting the natural increase in uncertainty.
✨ Key FeaturesDual-Threshold System (Visual vs. Alerts):Visual Channel: Draw the cone at a standard level (e.g., 2.0 Sigma) to see the general context.Background Alerts: Set alerts at a higher threshold (e.g., 3.0 Sigma) to be notified only during extreme volatility events, keeping your chart clean but your surveillance tight.Smart Dashboard:A customizable table displays the exact Trend Slope, Target Price, and Volatility Range in real-time.Includes color-coding (Green/Red) to instantly identify trend direction.Advanced Alert Engine:Breakout: Triggered when price exits the statistical cone.Re-Entry (Mean Reversion): Triggered when price returns into the cone after an excursion.Trend Filtering: Option to ignore signals that go against the main slope.Polyline Rendering: Uses Pine Script v6 dynamic polylines for smooth, curved visualization of the uncertainty cone (no blocky steps).Source Flexibility: Supports hlc3 (Typical Price) or hl2 input sources to reduce noise from candle wicks.
📚 User Manual & StrategiesStrategy 1: The "Volatility Squeeze" BreakoutSetup: Look for the cone to become narrow (low historical volatility).Trigger: Price breaks out of the cone's upper or lower boundary with a steep slope.Confirmation: The Dashboard Slope turns bright Green (Bullish) or Red (Bearish).Logic: A breakout from a low-volatility statistical range often signals the start of a new impulsive trend.Strategy 2: Mean Reversion (The "Rubber Band")Setup: Price extends far beyond the cone (e.g., hitting the 3.0 Sigma invisible wall).Trigger: Use the "Re-Entry" Alert. Wait for the price to close back inside the cone.Target: The central dashed orange line (The Regression Mean).Logic: Prices rarely stay at 3+ standard deviations for long. A return to the mean is statistically probable.Strategy 3: Trend Following with ConfluenceSetup: Enable "Filter by Trend" in the settings.Action: Only take Long trades if the Forecast Slope is positive, or Short trades if negative. Use the central dashed line as a dynamic trailing stop or support level.
⚙️ Settings GuideLookback Length: The number of past bars used to calculate the trend. (Default: 30)Forecast Horizon: How many bars into the future to project. (Default: 20)Widening Factor: Controls how fast the cone opens up. Higher values = wider cone end (more uncertainty).Alert Trigger (Sigma): The multiplier for backend alerts. Set this higher than the "Visual Channel" to filter noise.Source Data: Recommended set to hlc3 to include wicks in the calculation, or close for standard analysis.
⚠️ Disclaimer:This tool provides statistical projections based on past data. It does not guarantee future performance. Use it as part of a comprehensive trading strategy with proper risk management.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que la republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que la republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.