← Script Marketplace
Open-source scriptindicator/v1

Least Squares Moving Average

by Kodexius·@kodexius·

Plot the endpoint of a rolling linear-regression fit across the selected price source.

#moving-average#regression#trend
Least Squares Moving Average chart preview

Description

The Least Squares Moving Average fits a straight line to each rolling window and plots the fitted endpoint. This statistical approach can provide a smooth view of direction while remaining responsive to changes in the regression slope.

Open-source script. Everyone can inspect the source code, use the script on a chart, and save an editable copy.

Release notes

Version history · 1 published version

Version 1CurrentChart updatedLeast Squares Moving Average · Aug 31, 2026
Release notes

Initial classic indicator release.

View current source ↓
Source codempl-2.0View source

indicator("Least Squares Moving Average", { overlay: true });
const length = input.int("Length", 25, { min: 2, max: 500 });
const offset = input.int("Offset", 0, { min: 0, max: 100 });
const source = input.source("Source", "close");
plot(linreg(source, length, offset), { title: "LSMA", color: "#ff5252", lineWidth: 2 });
  

Community discussion

0 comments

Loading…

No comments yet. Start the discussion.