OPEN-SOURCE SCRIPT
Polynomial & Logarithmic Regression Channels [OnlyFibonacci]

Polynomial & Logarithmic Regression Channels [OnlyFibonacci] is an overlay indicator that fits a 2nd-degree polynomial regression curve to recent price action and builds dynamic standard deviation channels around that curve. Unlike a straight linear regression line or a simple moving average, the polynomial model captures curved trends — acceleration, deceleration, and rounded turning phases — while deviation bands quantify how far price has stretched from the fitted trend.
What Makes This Indicator Different
How It Works On each bar, the script collects the last N closing prices (default: 200) and fits the equation y = a + bx + cx² using matrix least-squares: β = (X'X)⁻¹X'Y. The regression line value at the current bar becomes the central trend curve. Residuals (actual price minus fitted value) across the lookback window are used to compute a sample standard deviation. Upper and lower channels are then plotted at user-defined σ multipliers. When Use Logarithmic Price Scale is enabled, prices are transformed with math.log() before regression and mapped back to the chart with math.exp() for display. The central line color reflects the instantaneous slope of the polynomial at the current bar: bright green when sloping up, bright red when sloping down.
Key Settings
How to Read the Chart
Dashboard Metrics
How to Use — Practical Interpretation Trend identification: Trade in the direction of the regression line color. A green (upward-sloping) curve supports bullish bias; red supports bearish bias. Pullback entries: In a strong trend, price pulling back toward the regression line or inner band while slope remains favorable can indicate a potential continuation zone — always confirm with your own structure or confluence. Mean reversion / exhaustion: When price pushes beyond the outer bands and dashboard shows Overbought or Oversold, the move may be statistically extended relative to the fitted curve. This does not guarantee reversal; it flags stretched conditions. Log vs. standard mode: Use log mode on higher timeframes and growth assets. Use standard mode on lower timeframes or when absolute price deviation is more relevant. Lookback tuning: Match lookback to your analysis horizon — e.g. 100–150 for swing trading, 200+ for position trend context.
Built-in Alerts
Recommended Setup
Credits Developed by OnlyFibonacci. Licensed under Mozilla Public License 2.0.
What Makes This Indicator Different
- []Matrix-based polynomial regression — Coefficients are solved via least-squares using Pine Script v6 matrix operations (matrix.new, matrix.transpose, matrix.mult, matrix.inv), not a basic ta.linreg() call. []Logarithmic price scale toggle — Switch between standard and log-price regression. Log mode is well suited for long-horizon assets where percentage growth matters more than absolute price moves. []Residual volatility channels — Inner (±1σ) and outer (±2σ) bands are built from the standard deviation of price residuals relative to the fitted curve, not from raw price volatility alone. []Live dashboard — Model type, channel position (%), residual volatility, and trend status (Overbought / Oversold / Neutral) are displayed in an upper-right table.
- Built-in alerts — Outer channel breaches and polynomial slope direction changes.
How It Works On each bar, the script collects the last N closing prices (default: 200) and fits the equation y = a + bx + cx² using matrix least-squares: β = (X'X)⁻¹X'Y. The regression line value at the current bar becomes the central trend curve. Residuals (actual price minus fitted value) across the lookback window are used to compute a sample standard deviation. Upper and lower channels are then plotted at user-defined σ multipliers. When Use Logarithmic Price Scale is enabled, prices are transformed with math.log() before regression and mapped back to the chart with math.exp() for display. The central line color reflects the instantaneous slope of the polynomial at the current bar: bright green when sloping up, bright red when sloping down.
Key Settings
- []Lookback Period (default 200) — Number of bars used to fit the polynomial. Higher values produce a smoother, slower-reacting curve; lower values track price more closely. []Use Logarithmic Price Scale — Enable for long-term trending markets (equities, crypto, indices). Keep off for short-term or range-bound analysis. []Inner / Outer Multipliers (default ±1.0 / ±2.0) — Control channel width. Wider multipliers reduce false overbought/oversold signals; tighter multipliers increase sensitivity. []Visual Style — Trend colors, band colors, fill transparency, and line widths.
- Dashboard — Toggle the info table and adjust text size.
How to Read the Chart
- []Polynomial Regression line — The dynamic trend curve. Color shows current slope direction. []Inner bands (±1σ) — Normal fluctuation zone around the trend. Pullbacks into inner bands within a trending market may offer continuation setups. []Outer bands (±2σ) — Statistical stretch zone. Price beyond outer bands signals extended deviation from the fitted trend. []Channel fills — Soft shaded areas between bands help visualize channel structure without cluttering the chart.
Dashboard Metrics
- []Model Type — "Polynomial" (standard scale) or "Log-Poly" (logarithmic scale). []Channel Position (%) — Where price sits within the outer channel (0% = outer lower, 100% = outer upper). Values above 80% or below 20% are highlighted. []Residual Volatility — Dispersion of price around the fitted curve, shown as a percentage. []Trend Status — Overbought (above outer upper), Oversold (below outer lower), or Neutral (inside outer bands).
How to Use — Practical Interpretation Trend identification: Trade in the direction of the regression line color. A green (upward-sloping) curve supports bullish bias; red supports bearish bias. Pullback entries: In a strong trend, price pulling back toward the regression line or inner band while slope remains favorable can indicate a potential continuation zone — always confirm with your own structure or confluence. Mean reversion / exhaustion: When price pushes beyond the outer bands and dashboard shows Overbought or Oversold, the move may be statistically extended relative to the fitted curve. This does not guarantee reversal; it flags stretched conditions. Log vs. standard mode: Use log mode on higher timeframes and growth assets. Use standard mode on lower timeframes or when absolute price deviation is more relevant. Lookback tuning: Match lookback to your analysis horizon — e.g. 100–150 for swing trading, 200+ for position trend context.
Built-in Alerts
- []Overbought — price above outer upper channel []Oversold — price below outer lower channel []Trend slope turned bullish — polynomial derivative crossed above zero []Trend slope turned bearish — polynomial derivative crossed below zero
Recommended Setup
- []Apply to a clean chart with no other overlapping indicators for clearest visualization. []Start with default settings (200 lookback, ±1σ / ±2σ bands). []Test on your preferred timeframe and symbol before relying on signals. []Combine with support/resistance, volume, or higher-timeframe trend for confluence — this tool provides statistical context, not standalone trade signals.
This indicator is a quantitative analysis tool for educational and informational purposes only. It does not constitute financial advice, investment recommendation, or a guarantee of future performance. Past behavior of regression channels does not predict future results. Always manage risk and conduct your own due diligence before making trading decisions.
Credits Developed by OnlyFibonacci. Licensed under Mozilla Public License 2.0.
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 cualquier republicación del código está sujeta a nuestras Normas internas.
Love for AlgoTrading
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 u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga 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 cualquier republicación del código está sujeta a nuestras Normas internas.
Love for AlgoTrading
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 u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.