OPEN-SOURCE SCRIPT

Robust Regression Residual Bands [Pineify]

3 267
Robust Regression Residual Bands [Pineify]

Overview
This overlay fits a rolling line while bounding influence from unusual closes. It shows a robust center, two MAD shells, confirmed extremes, and an optional dashboard. It is context, not a forecast.

Problem Definition
Least-squares channels and standard deviation magnify large errors. One gap, wick, or bad print can rotate the line and widen its bands, changing both the reference and the meaning of “far.” Short windows add noise; long ones preserve distortion. The invariant is that ordinary observations define the path, extremes stay visible, and their influence remains bounded.

Design Rationale
Regression stays because slope and residual distance answer different questions. Finite Huber-style refits replace unrestricted influence: residuals inside a threshold keep full weight; those outside receive progressively less. Hard deletion was rejected because values switch abruptly at a cutoff. Final scale uses median absolute deviation (MAD) times 1.4826. MAD resists isolated extremes but is less efficient for Gaussian errors. Two passes balance refreshed weights with bounded workload; users may select one to three.

Key Features
  • Rolling regression with bounded influence refits.
  • Two shells sized from final residual MAD.
  • Center color for normalized slope.
  • Confirmed outer-entry diamonds.
  • Optional bar color and dashboard for residual z, slope/MAD, scale, window, and passes.


How It Works
Each bar loads a chronological rolling window and fits an equal-weight line. It finds every residual, their median, and median absolute distance from that median. MAD times 1.4826 becomes robust scale; minimum tick prevents zero division.

Each distance is compared with clipping threshold times scale. Inside values keep weight 1. Outside values receive threshold divided by distance, smoothly capping influence. The line is refitted for the selected passes; residual median and MAD are then recomputed. Displayed center is the newest fit plus median residual.

Bands equal center plus or minus selected MAD multiples. Residual z divides current distance by scale; slope divided by scale controls color. A full window without missing data is required. Open-bar values can change; markers and alerts require confirmation.

How Multiple Indicators Work Together
These are causal stages, not unrelated indicators. Regression supplies direction but needs clipping to limit leverage. Clipping needs scale, and MAD prevents the same extreme from dominating it. Final residual measures price against the stabilized path; normalized slope separates direction from dispersion. Without refitting, bands inherit a tilted center; without scale, distance is not comparable. All visuals expose one model.

Trading Ideas and Insights
A confirmed outer entry means the close is unusual relative to current path and scale; it does not imply reversal. Alignment with strong slope can describe expansion, while repeated extremes with flattening slope can motivate a balance review. Alternating center crosses expose noise. Compare states with structure, liquidity, events, and risk controls. The script provides no entries, stops, sizing, or expected returns.

Unique Aspects
The contribution couples bounded influence refits with a median-centered MAD field. Common channels let an extreme affect slope and width through squared error. Here distance sets a smooth influence cap, the line is rebuilt, and final residuals size the tunnel. Median residual shifts the newest fit instead of assuming zero arithmetic mean. Center is primary, shells encode distance, and amber diamonds encode confirmed entries—not probability.

How to Use
  1. Add it to a standard chart and wait for a full window.
  2. Choose a window matching the horizon and review several regimes.
  3. Read center color as normalized direction and bands as robust distance.
  4. Use the dashboard to compare raw and scale-relative movement.
  5. Alert on confirmed outer entry or center crossing, then apply independent context and risk rules.

Secondary layers can be disabled without changing the model.

Customization
Short windows adapt faster and vary more; long ones smooth more and retain old regimes. Extra refit passes can limit leverage further but cost computation and may underweight a true break. Lower clipping resists extremes sooner; higher clipping approaches ordinary regression. MAD multiples set tunnel thresholds, with a minimum shell gap enforced. Visual layers and palette are independent. Defaults are not universal optima.

Assumptions and Limitations
The model assumes a useful local line and comparable source data. Curves, breaks, gaps, rolls, illiquidity, adjusted history, and non-standard charts weaken it. Robust weights bound influence but cannot label an extreme as error or regime change. Results lag, parameters matter, and small MAD makes flat markets sensitive to the tick floor.

Open-bar values may change. Confirmed alerts still depend on feed and settings. Missing data restarts warm-up. The script has no volume, order flow, higher-timeframe request, future value, pivot, or simulation. It estimates neither reversal probability nor fair value, execution, risk, or profit. Outer distance is deviation, not proof of return.

Conclusion
Bounded refits stabilize rolling path, MAD stabilizes scale, and the tunnel exposes both. Treat distance and direction as lagging context, not a forecast; use independent confirmation.

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。