Python · Indicator Code
RL10 - Regression Line in Python
The fitted endpoint of a 10-bar linear regression - a smoothed read of true price that filters candle noise.
Verified. Python and JavaScript implementations agree to
7.11e-14 on a 60-bar reference price series (canonical Python (np.correlate) vs JavaScript (loop) - float64 round-off only).Python
import numpy as np
def rl10(values, n=10):
"""RL10 - the fitted value of an n-bar linear regression at the most
recent bar (the regression-line 'endpoint'). Canonical Owl Group Trading
implementation; vectorized with np.correlate for O(N) speed.
Returns an array the same length as `values`; the first n-1 entries are
NaN (not enough lookback). n defaults to 10, hence 'RL10'.
"""
values = np.asarray(values, dtype=float)
out = np.full(len(values), np.nan)
if n <= 0 or len(values) < n:
return out
# Fixed regression weights for x = [0, 1, ..., n-1] so the endpoint value
# equals sum(w_i * y_i) for each sliding window.
x = np.arange(n)
x_mean = (n - 1) / 2.0
x_diff = x - x_mean
denom = float(np.sum(x_diff ** 2))
if denom == 0:
return out
w = 1.0 / n + x_mean * x_diff / denom
out[n - 1:] = np.correlate(values, w, mode="valid")
return out
Other platforms: JavaScript
← RL10 - Regression Line (all platforms) · All indicators · Glossary concept
← RL10 - Regression Line (all platforms) · All indicators · Glossary concept
Improve Your Craft Every Morning
A short note from Dr. Ken Long on the craft of trading. One idea to think about and work on that day, drawn from decades of teaching and live trading. Free.
Your email:
Tue–Fri mornings. Unsubscribe anytime. No spam, no hype.