Files
wickra/docs/wiki/indicators/statistics/Indicator-LinRegAngle.md
T
kingchenc 6643f7a81d F13b: add True Range, Chaikin Volatility, Z-Score and Linear Regression Angle
Second half of the eight indicators that fill out the new family taxonomy.

- Rust core: true_range.rs (TrueRange — the raw single-bar volatility ATR
  averages), chaikin_volatility.rs (ChaikinVolatility — rate of change of a
  smoothed high-low spread), z_score.rs (ZScore — price normalised against
  its rolling mean and standard deviation) and linreg_angle.rs (LinRegAngle
  — the rolling regression slope as a degree angle). Each with a full
  Indicator impl, runnable doctest and reference / property / warmup /
  reset / batch==streaming tests.
- Python / Node / WASM: classes wired through all three bindings (ZScore
  and LinRegAngle ride the scalar macros where possible) plus .pyi stubs
  and __init__.py / __all__ entries.
- Wiki: four new Indicator-*.md pages.

The eight-family taxonomy restructure (Overview / Home / README / folder
layout) lands next in F13c.

cargo fmt + clippy (core/wickra/data/wasm/node) clean; 508 core tests,
25 data tests and 74 doctests green.
2026-05-22 21:06:36 +02:00

3.8 KiB
Raw Blame History

LinRegAngle

Linear Regression Angle — the slope of the rolling least-squares fit, expressed as an angle in degrees.

Quick reference

Field Value
Family Price Statistics
Input type f64 (price)
Output type f64
Output range (90°, +90°)
Default parameters period = 14 (Python)
Warmup period period
Interpretation Steepness of the trend; sign is direction, magnitude is pitch.

Formula

LinRegAngle = atan(LinRegSlope) · 180 / π

The angle carries exactly the same information as LinRegSlope — positive while price trends up, negative while it trends down — but maps the unbounded slope through atan onto (90°, +90°). That bounded, price-unit-free scale makes "how steep is the trend" comparable at a glance and across instruments. This is TA-Lib's LINEARREG_ANGLE.

Parameters

period — the regression window. Must be at least 2 (a line needs two points). The Python binding defaults it to 14; the Rust and Node constructors require it explicitly.

Inputs / Outputs

From crates/wickra-core/src/indicators/linreg_angle.rs:

impl Indicator for LinRegAngle {
    type Input = f64;
    type Output = f64;
    // update(&mut self, input: f64) -> Option<f64>
}

LinRegAngle is a scalar indicator: it consumes one f64 price per step. Because Input = f64 it can sit inside a Chain.

Warmup

LinRegAngle::new(14).warmup_period() == 14. The first value lands once the window holds a full period prices.

Edge cases

  • period < 2. Rejected at construction — a regression line is undefined for fewer than two points.
  • Unit slope. A series rising by exactly 1 per step has slope 1, and atan(1) = 45°.
  • Flat series. A constant input has slope 0 and therefore angle 0.
  • Reset. angle.reset() clears the rolling regression window.

Examples

Rust

use wickra::{BatchExt, Indicator, LinRegAngle};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut angle = LinRegAngle::new(5)?;
    // Closes rising by 1 per step -> slope 1 -> atan(1) = 45 degrees.
    let out = angle.batch(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
    println!("{:?}", out);
    Ok(())
}

Output:

[None, None, None, None, Some(45.0), Some(45.0)]

Python

import numpy as np
import wickra as ta

angle = ta.LinRegAngle(5)
print(angle.batch(np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])))

Output:

[ nan  nan  nan  nan 45. 45.]

Node

const ta = require('wickra');
const angle = new ta.LinRegAngle(5);
console.log(angle.batch([1, 2, 3, 4, 5, 6]));

Output:

[ NaN, NaN, NaN, NaN, 45, 45 ]

Interpretation

The angle is read like a slope: sign gives trend direction, magnitude gives how steeply price is pitched. Because it is bounded to ±90° it is convenient for thresholds — e.g. "only trade with the trend while the angle exceeds 30°" — and for comparing trend pitch across instruments with different price scales, which the raw LinRegSlope cannot do.

Common pitfalls

  • Reading degrees as a price quantity. The angle depends on the chart's implicit scaling; treat it as a relative steepness gauge, not an absolute.
  • Tiny periods. period = 2 reduces the fit to the last difference.

References

The angle of an ordinary least-squares fit to a rolling price window; matches TA-Lib's LINEARREG_ANGLE.

See also