Skip to content
Open RaamTrade

StandardErrorBands — Standard Error Bands

The regression line with bands a multiple of the standard error away. Unlike Bollinger, the centreline is a fitted trend rather than an average, and the bands narrow when the trend is clean rather than when volatility is low — a different question, often a more useful one.

Signature

StandardErrorBands(period, multiplier, on=<source>)
Argument Type Required Notes
period int Param or literal Yes Regression window. Default 20, bounds 3–400.
multiplier float Param or literal Yes Band width in standard errors. Default 2.0, bounds 0.1–10.0.
on= symbol, OHLCV field, or indicator No Source. Defaults to the trade symbol’s close.

Formula

$$ \text{mid} = \text{LSMA}(n), \quad \text{upper/lower} = \text{mid} \pm m \cdot SE $$

Warmup

period bars; all three outputs track the close until then.

Reading the value

seb.upper
seb.mid
seb.lower

Multi-value: cannot be chained onto or crossed.

Example

class ErrorBandFade(Strategy):
"""Fade a stretch outside a tight regression channel."""
trade = Symbol()
sizing = FixedCapital()
def execute(self):
seb = StandardErrorBands(20, 2.0, on=self.trade)
if self.trade.close < seb.lower and self.trade.is_flat:
self.buy(self.trade, reason="Below the channel")
if self.trade.close > seb.mid and self.trade.is_long:
self.sell(self.trade, self.trade.position, reason="Back to the fit")

Notes

  • Jon Andersen, TASC (1996). Andersen smoothed both the line and the bands over three bars; this ships the unsmoothed form so the outputs match LSMA and StandardError exactly.
  • Proven by an assert-via-trade run on SPY daily (all three outputs matched a strategy-side regression to 1e-3 on every bar; zero alarm trades).