Indicator history Unfortunately, there is no mention on the Internet who was the first to apply the least squares method for stock prices. The first mentions appear only after the 2000s, so we can say that this indicator is “new” and not fully explored. If you have more accurate information, share with us in the comments.

Input parameters:

LSMA_Period – period for calculating the moving average by the least squares method

  • Prediction – the number of candles used to construct the predicted moving average
  • Display_Bars – number of displayed bars (at 0, all are displayed)
  • The Least Square Moving Average indicator allows you to assess the direction of the market movement and its possible reversals

Conclusion Least Square Moving Average is an interesting subtype of a moving average that does not lag behind and fully reflects price movements. It helps to determine the direction of the trend, possible reversal points, as well as stop loss and take profit.

The LSMA indicator can be used in all moving average strategies.

Calculation formula

The indicator is based on the least squares method to find the straight line that best matches the data for the selected period.

  • Because we are looking for the y-value at the current point (x = 0), so we need the coefficient b. The coefficient a and b is found from the system of equations:
  • Where xi is the ordinal number of the candlestick from right to left, yi = the price value corresponding to the candle, n is the quantity candles (period).

Examples of using

One of the signals is the leading of the moving average according to the method of least squares of the maximum or minimum price.

  • Example for a buy and sell signal: An example using two LSMA (50) with Prediction = 5 and Prediction = 0.

Source