Std Error Bands
The Standard Error Bands node fits an OLS linear regression to the rolling window and outputs three series: a middle band (the fitted regression value at the latest bar), an upper band (fitted + multiplier × std error), and a lower band (fitted − multiplier × std error). Standard error bands expand when regression fit quality is poor and contract when the trend is clean — unlike Bollinger Bands, they are based on trend linearity rather than absolute deviation.
Algorithm
- ▸Fit OLS to window pairs (i, v[i]): slope β₁ and intercept β₀
- ▸fitted = β₀ + β₁ × (period − 1) (value at last bar)
- ▸SSR = Σ(y − ŷ)² over all non-null pairs
- ▸stdError = √(SSR / (n − 2)) — requires n ≥ 3 for 2 degrees of freedom
- ▸upper = fitted + multiplier × stdError
- ▸middle = fitted
- ▸lower = fitted − multiplier × stdError
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| period | number | 21 | Rolling window size. Minimum 3. |
| multiplier | number | 2 | Std error multiplier for band width. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input | number[] | Source numeric array |
| Outputs | ||
| upper | number | null | Fitted value + multiplier × std error at each bar |
| middle | number | null | OLS fitted (predicted) value at the last bar of the window |
| lower | number | null | Fitted value − multiplier × std error at each bar |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned with upper / middle / lower |
Use Cases
Trend-Relative Channel
Price touching the upper band while the trend is steep and R² is high is a trend-continuation signal. Price returning from outside the band is a mean-reversion entry.
Breakout Filter
Narrow std error bands (small stdError) confirm a clean linear trend. Wide bands warn that the current direction lacks linearity and breakout trades carry higher noise risk.
Dynamic Stop Placement
Use the lower band (in an uptrend) as a dynamic, regression-anchored trailing stop — it tightens as the trend becomes more linear and widens when price becomes erratic.