OPEN-SOURCE SCRIPT

Inverse-Variance Slope Spectrum [forexobroker]

269
Inverse-Variance Slope Spectrum [forexobroker] runs five linear regressions of different lengths in parallel and blends their slopes into a single consensus, trusting each regression in proportion to how well it actually fits the data. The result is a noise-robust trend estimate whose sign sets the bias, with an adaptive linear-regression signal line timing entries. It is a statistically weighted answer to the classic problem of picking one regression length.

🔶 ALGORITHM

1. For each of five regression lengths, compute the slope as ta.linreg(close, L, 0) minus ta.linreg(close, L, 1).
2. For each length, compute the price-vs-bar-index correlation r, and a residual variance = price variance x (1 - r^2).
3. Assign each regression a weight of 1 / residual variance, so tighter-fitting lengths count more.
4. Combine the five slopes into an inverse-variance-weighted consensus slope.
5. The consensus slope's sign sets the regime/bias (positive = up, negative = down); an optional Min |Slope| x ATR gate filters weak slopes.
6. A close-cross of the adaptive linear-regression signal line in the bias direction times the entry. ATR is tracked for context.

🔶 SIGNAL LOGIC

- Buy: in-session AND |consensus slope| passes the ATR gate AND slope regime is up AND close crosses over the signal line AND not already long AND cooldown elapsed AND barstate.isconfirmed (position-locked).
- Sell: in-session AND |consensus slope| passes the ATR gate AND slope regime is down AND close crosses under the signal line AND not already short AND cooldown elapsed AND barstate.isconfirmed (position-locked).
Only fires when the consensus slope regime agrees with the signal-line cross.

🔶 INPUTS

- Spectrum: five regression lengths forming the slope spectrum; default Reg Length 1 = 10 (through Reg Length 5 = 89).
- Spectrum: Adaptive Signal Linreg length used as the entry signal line; default Adaptive Signal Linreg = 20.
- Spectrum: ATR length for the slope gate and context; default ATR Length = 14.
- Signal Logic: Min |Slope| x ATR optional minimum consensus-slope magnitude; default Min |Slope| x ATR = 0.0 (off).
- Signal Logic: Cooldown bars between signals; default Cooldown Bars = 5.
- Filters: optional session restriction with a session window; default Restrict to Session off.
- Visual: signal-line plot, dashboard, 3-layer glow, and buy/sell/background colors; signal line default on.
- Visual: dashboard reports regime, consensus slope, slope/ATR, signal line and weight sum; dashboard default on.

🔶 ALERTS

IVS Buy, IVS Sell, IVS Any Signal, IVS Slope Bull, IVS Slope Bear, IVS Signal Up, IVS Signal Down, IVS Slope Zero, IVS Strong Slope, IVS Regime Flip, IVS Any Signal Cross, IVS Webhook JSON.

🔶 LIMITATIONS

- Computational cost is higher than a single regression: it runs five regressions plus correlation and variance each bar.
- Needs warm-up bars up to the longest regression length before the consensus stabilises.
- Inverse-variance weighting reduces but does not eliminate lag inherent to linear regression.
- The consensus describes trend slope, not magnitude of future move; ranging markets can still whipsaw.
- Defaults are tuned for liquid instruments; very noisy symbols may need a Min |Slope| gate.

כתב ויתור

המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.