StandardError — Standard Error
How far price scatters around its own regression line. Low means the straight line explains
the move; high means the trend is a bad description of what happened. The natural companion to
LinearRegressionSlope — slope tells you the direction, this tells you whether to believe it.
Signature
StandardError(period, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
period |
int Param or literal | Yes | Regression window. Default 20, bounds 3–400 (three points minimum for a residual). |
on= |
symbol, OHLCV field, or indicator | No | Source. Defaults to the trade symbol’s close. |
Formula
$$ SE = \sqrt{\frac{\sum_i (C_i - \hat{C}_i)^2}{n-2}} $$
with $\hat{C}$ the least-squares fit. The n − 2 denominator is the regression convention: two
degrees of freedom go to the slope and intercept.
Warmup
period bars; 0 until then.
Reading the value
se.valuese.value < atr.valueExample
class CleanTrendOnly(Strategy): """Trade the slope only when the fit is tight.""" trade = Symbol() sizing = FixedCapital()
def execute(self): se = StandardError(20, on=self.trade) slope = LinearRegressionSlope(20, on=self.trade) atr = ATR(14, on=self.trade) if slope.value > 0 and se.value < atr.value and self.trade.is_flat: self.buy(self.trade, reason=f"Clean uptrend, SE {se.value:.2f}") if slope.value < 0 and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Slope down")Notes
- Standard regression statistics.
- Proven by an assert-via-trade run on SPY daily (matched a strategy-side residual computation to 1e-3 on every bar; zero alarm trades).
- In price units — compare it against ATR or divide by price to make it portable.