- Indicator history
- Description and input parameters
- Calculation formula
- Examples of using
- Download indicator for MT4 and MT5
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. This has become possible thanks to the increase in computing power. If you have more accurate information, share with us in the comments, we will supplement the section.
The Least Square Moving Average indicator allows you to assess the direction of the market movement and its possible reversals. The indicator is a line that is displayed in the price window. The least squares moving average algorithm plots a regression line on the graph at the current point. That is, the LSMA tries to predict the price behavior, what it would be if the regression line continued.
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 by the least squares method, provided that the rate of its (decline or growth remains);
Display_Bars – number of displayed bars (at 0, all are displayed).
The first difference is that LSMA is a mathematical expected line and is related to price through a formula. Therefore, it can show values that prices have never shown.
The second is that the least squares moving average is much more responsive than any other moving average. Given that its calculation accuracy will be higher. The figure shows an exponential moving average with parameters 50 and 15 and LSMA with a value of 50.
An interesting feature of this indicator is the Prediction parameter. It draws a line, which would be if the price moved at the same speed for a given number of candles. In fact, we can determine the points at which the price stopped. To do this, add a least squares moving average with period n (Prediction = 0) and exactly the same one with parameter n and Prediction not equal to 0. It follows from the formula that if the speed is 0, then the LSMA line will coincide with the LSMA + Prediction line.
The indicator is based on the least squares method to find the straight line that best matches the data for the selected period. Therefore, we write the equation of the straight line:
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 is the price value corresponding to the candle, n is the quantity candles (period).
Consider an example: We have 5 candles
For the sake of a more compact notation, the “counter” variable can be omitted, since it is clear that the summation is carried out from 1 to n = 5.
Substituting the numbers into the system and performing the calculations, we get the value b = 41.12. In this case, the value of the usual moving average will be 41.057. For period 5, we already see a small difference. At the same time, the LSMA price is closer to the last price (42.005) than the usual moving average.
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 of a sell signal:
Example for a buy and sell signal:
An example using two LSMA (50) with Prediction = 5 and Prediction = 0.
Of course, all strategies for crossing two or three moving averages and many others can be used with the Least Square MA indicator. Thus, improving its response and adaptability to changes in its strategy.
You can try demo versions of the indicators for free in the MetaTrader 4 or 5 strategy tester using the links below.
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. In this case, the signals will be faster, while many of the noise will be mathematically smoothed, but there is also the danger of false signals.