LinearRegressionAngle — Linear Regression Angle
תוכן זה אינו זמין עדיין בשפה שלך.
The regression slope expressed as an angle in degrees. Bounded to ±90 regardless of the instrument’s price, which makes it readable at a glance — though the mapping still depends on the chart’s scale, so it is a presentation of the slope, not a normalisation of it.
Signature
LinearRegressionAngle(period, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
period |
int Param or literal | Yes | Regression window. Default 14, bounds 2–400. |
on= |
symbol, OHLCV field, or indicator | No | Source. Defaults to the trade symbol’s close. |
Formula
$$ \text{angle} = \arctan(\text{slope}) \cdot \frac{180}{\pi} $$
Warmup
period bars; 0 until then.
Reading the value
ang.valueang > 45ang.crossed_above(0)Example
class SteepTrend(Strategy): """Only join a trend once the regression is genuinely steep.""" trade = Symbol() sizing = FixedCapital()
def execute(self): ang = LinearRegressionAngle(14, on=self.trade) if ang.value > 45 and self.trade.is_flat: self.buy(self.trade, reason=f"Angle {ang.value:.0f} deg") if ang.value < 0 and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Angle negative")Notes
- TA-Lib LINEARREG_ANGLE.
- Proven by an assert-via-trade run on SPY daily (matched a strategy-side arctangent of the OLS slope to 1e-3 on every bar; zero alarm trades).
- The angle is only meaningful relative to the price scale: one point per bar on a $10 stock
and on a $600 index give the same angle here but are wildly different moves. Prefer
LinearRegressionSlopedivided by price for cross-instrument work.