Skip to Content
ChartIndicatorsLinearRegression

LinearRegression

LinearRegression is a moving linear regression: on every bar a straight line is fitted to the last bars, and the indicator line follows its end point (LSMA). In a steady trend this line follows the price without lag, unlike a simple moving average; the channel around it shows how far the price usually strays from the line.

The indicator is drawn over the price chart.

How to read it

  • The slope of the line is the direction of the move.
  • The price leaving the channel means the move is stretched relative to the current trend.
  • A narrowing channel means the price moves steadily along the line.

This is a moving regression over past bars: unlike a regression channel drawn over a selected stretch, it does not repaint history.

How it is calculated

  1. A straight line is fitted by least squares to the prices set in Source over the last Period bars. The Regression line is the value of this line on the current bar.
  2. The standard deviation of the prices from the line is calculated.
  3. The channel bounds: the regression line ± StdDev × the standard deviation.

The line appears once Period bars are available. If the price did not change over the whole window, the slope is zero.

Parameters

ParameterDescriptionDefault
PeriodHow many last bars the line is fitted to. At least 2.25
StdDevThe channel width in standard deviations; 0 means no channel, only the line.2
SourceThe bar price used in the calculation: Close — the close, Median — (High + Low) / 2, Typical — (High + Low + Close) / 3.Close

Plots

ParameterDescriptionDefault
RegressionThe end point of the regression line (LSMA).Orange, solid, width 1
ChannelThe upper and lower bounds of the channel.Blue, solid, width 1
FillThe area between the channel bounds.Semi-transparent blue

Style

The lines have the Plot (show the line), Label (show the last value on the right scale), Color, Width (1–5) and Style (Solid, Dashes, Dots) fields. The fill has the Fill (show the fill) and Color fields.

How to add an indicator to the chart is described in Adding an indicator; parameters are changed in the indicator manager.

Last updated on