Skip to content

Least Squares Moving Average ​

Least squares line through the last N closes, at its end.

Kind indicator · Drawn on the price pane

Try it ​

On the chart, press / and choose Least Squares Moving Average under Moving averages. To change it, copy the source below into the AlphaScript editor.

Inputs ​

InputTypeDefault
Lengthint25
Offsetint0
Sourcesource"close"
Colorcolor"#2962FF"

Source ​

From packages/alphascript/indicators/lsma.as.js.

js
indicator({ name: "Least Squares Moving Average", shortTitle: "LSMA", overlay: true });
const length = input.int("Length", 25, { min: 1 });
const offset = input.int("Offset", 0, { min: -500, max: 500 });
const src = input.source("Source", "close");
plot(ta.linreg(src, length, offset), { title: "LSMA", color: input.color("Color", "#2962FF", { group: "Style" }) });

AlphaScript language v0.1 · runtime 0.2.0