Indicator Formula

Technical Details — Least Squares Moving Average (LSMA)
Section titled “Technical Details — Least Squares Moving Average (LSMA)”Overview
Section titled “Overview”The Least Squares Moving Average (LSMA) fits a linear regression line to the last n prices and uses the end point as its value. This approach projects the trend forward, making LSMA one of the most responsive moving averages.
Mathematical Derivation
Step 1 — Fit Linear Regression
Section titled “Step 1 — Fit Linear Regression”Purpose: Find the best-fit line through the last n prices.
$$y = a + b \times x$$ $$b = \frac{n\sum xy - \sum x \sum y}{n\sum x^2 - (\sum x)^2}$$ $$a = \frac{\sum y - b \sum x}{n}$$
Where:
- $$x$$ = Bar index (1 to n)
- $$y$$ = Closing prices
- $$b$$ = Slope
- $$a$$ = Intercept
What This Measures: The best-fit line through recent price history
Step 2 — Calculate Endpoint
Section titled “Step 2 — Calculate Endpoint”Purpose: Use the regression line’s endpoint as the LSMA value.
$$LSMA[t] = a + b \times n$$
What This Measures: The projected end of the regression line — the trend-adjusted average
Compact Formula Summary
$$b = \frac{n\sum xy - \sum x \sum y}{n\sum x^2 - (\sum x)^2}$$ $$a = \frac{\sum y - b \sum x}{n}$$ $$LSMA[t] = a + b \times n$$
Default Parameter: Period (n) = 14
Complete Calculation Example
LSMA fits a regression line to prices. If the trend is upward (positive slope), LSMA’s endpoint projects ahead of the average — capturing direction better than standard MAs.
Key Takeaways from the Example
- Regression-Based: Uses statistical line fitting rather than simple averaging
- Trend Projection: The endpoint naturally captures trend direction and speed
- Very Responsive: Reacts quickly to trend changes because the slope adjusts immediately
- Can Lead Price: In strong trends, LSMA projects ahead, appearing to predict price movement