Charts See the terminal

Least Squares Moving Average (LSMA)

The end point of a straight line fitted through the last 25 bars, showing where the recent trend puts price now rather than where it has been on average.

Moving Average Add to chart

Live LSMA preview · BTC/USDT · Binance

What is LSMA?

The least squares moving average fits a straight line through the last n prices, the line that sits as close as possible to all of them, and plots where that line ends at the current bar. A simple average answers "what was the average price"; this answers "where does the recent trend say price is now". It therefore sits closer to current price than a simple average of the same length and turns sooner.

LSMA describes the recent trend as a straight line. It does not forecast where price goes next, it does not measure how well the line fits, and when price is not moving in a straight line it can swing further than an ordinary average.

How to use LSMA

  • Price above or below the line. Price holding above LSMA is read as context for an uptrend, below it for a downtrend.
  • The slope. A rising LSMA means the fitted line through the window is tilted upwards. A flattening one means the recent trend has lost its tilt.
  • LSMA against a simple average. In a steady trend LSMA runs ahead of a simple average of the same length, because it projects the trend to the current bar instead of averaging it. The two converge when price goes flat.
  • Period length. Shorter fits the line through fewer bars and reacts sooner; longer is steadier and slower.

These are ways to read the line, not entry signals on their own.

Settings

SettingDefaultWhat it changes
Length25 Bars the straight line is fitted through. Lower follows price more closely and is noisier; higher is smoother and later. Minimum 1.
SourceClose Which price each bar contributes. Open, high, low and the averaged sources such as hl2 and hlc3 are also available.

Adjust the period and price source in the indicator settings.

Calculation

Each bar, the indicator fits a least-squares straight line through the last n prices, with bar position on one axis and price on the other, and plots that line's value at the newest bar:

fit   price = a + b * x   over the last 25 bars (x = 0 oldest ... 24 newest)
LSMA  = a + b * 24        (the line's value at the current bar)

Equivalent form:
LSMA  = 3 * WMA(price, 25) - 2 * SMA(price, 25)

The least-squares line is the one that minimises the sum of the squared vertical distances from each price to the line. Its end point is the indicator's value. The equivalent form shows why it is faster than either average: it pushes a weighted average further in the direction it already leads a simple one.

The line is recalculated from scratch on every bar over its own window, so each value depends only on the last n prices. The first value appears once a full window is available, on bar 25 with the default length.

Limitations

  • It assumes a straight line. When price curves or reverses inside the window, the fitted line is a poor description and its end point can swing sharply.
  • It overshoots at turns. Projecting the trend to the current bar puts the line ahead of a plain average, so after a reversal it can sit beyond price for a few bars.
  • Sideways markets produce frequent crossings. With no trend, the fitted slope flips back and forth and price crosses the line often.
  • It depends on timeframe, period and source. The same indicator gives a different line on 15m than on 1D, or on close against hl2.
  • It is not a strategy. On its own it carries no risk management, sizing or exit.

Frequently asked questions

The least squares moving average is the end point of a straight line fitted by least squares through the last n prices. It is also called the linear regression line or end-point moving average. Each bar the line is fitted again over the new window.

A simple average reports the mean of the window, which lags in a trend because it sits in the middle of the window's prices. LSMA projects the window's trend to the current bar, so it sits closer to price and turns sooner, at the cost of swinging further when the fit is poor.

The default is 25. Shorter windows react faster and are noisier; longer windows describe the broader trend and react later. Choose the length for the timeframe you trade and test it.

Yes. The indicator has two inputs: Length, default 25 with a minimum of 1, and Source, default close. Open the indicator's settings on the chart to change them. Source accepts open, high, low, close and the averaged sources such as hl2 and hlc3.

No. Each value is the end of a line fitted through that bar and the bars before it, and it is not recalculated once the bar has closed. The plotted line joins those end points; the full fitted line for an older bar is never redrawn over later bars. The current candle's value moves while that candle is live and settles when it closes.

Use the Add to chart button at the top of this page. It opens BTC/USDT on Binance in the Altrady Charts terminal with the built-in Least Squares Moving Average already applied. On any other market, open the indicator picker on the chart and choose Least Squares Moving Average from the Moving Average group.

Add to chart