Linear regression slope  indicator for MetaTrader 5
Linear regression fits the following equation of a straight line to price data:
y[x] = y0 + b*x
where:
 x is a bar number (x=1..n);
 y[x] is the corresponding price (open, close, median etc);
 b is a proportionality coefficient
 y0 is a bias.
The linear regression slope, given by this indicator, is equal to a normalized version of the coefficient b.
The formula for b is:
b = (n*Sxy  Sx*Sy)/(n*Sxx  Sx*Sx)
where:
 Sx = Sum(x, x = 1..n)= n*(n + 1)/2;
 Sy = Sum(y[x], x = 1..n);
 Sxx = Sum(x*x, x = 1..n) = n*(n+1)*(2*n+1)/6;
 Sxy = Sum(x*y[x], x = 1..n);
 n is the period of LRS (input parameter Per).
The denominator of b can be simplified to:
n*Sxx  Sx*Sx = n*n*(n1)*(n+1)/12
Finally, the whole equation for b can be simplified to
b = 6*(2*Sxy/(n + 1)  Sy)/n/(n  1)
The coefficient b is not normalized. It has to be normalized if we want LRS to have a roughly the same range for different currency pairs. It is convenient to normalize b by dividing it by either a simple moving average (SMA) or a linear weighted moving average (LWMA), which are given by:
SMA = Sy/n
LWMA = 2*Sxy/n/(n + 1)
The corresponding versions of LRS are given by
LRS_SMA = b/SMA = 6*(2*Sxy/Sy/(n + 1)  1)/(n + 1)
LRS_LWMA = b/LWMA = 6*(1  (n + 1)*Sy/Sxy/2)/(n + 1)
These two versions of normalization are almost indistinguishable. So, the SMA normalization was chosen for the indicator. Also, because of very small values of the LRS, the indicator values are calculated and plotted in parts per 100 thousand to fit roughly into the range of 100 to +100.
Download Linear regression slope  indicator for MetaTrader 5
Related News

MetaTrader 4

MetaTrader 5




Taiwan Stocks Will Soar to Record in 2020, Analysts Say
09.12.2019 21:06
(Bloomberg)  This year’s unexpected 20% rally in Taiwan stocks is poised to close a final chapter in the history of its financial markets. The Taiex index is within 7% of its alltime high from 1990, a milestone that analysts say will likely be topped next year. That year marked the bursting of the bubble in Taiwan stocks, which had rallied even
Read more →
Erdogan says Turkey to attain singledigit interest rates, inflation in 2020
09.12.2019 21:03
ANKARA (Reuters)  Turkey will attain singledigit interest rates and inflation in 2020, President Tayyip Erdogan told state broadcaster TRT Haber on Monday, adding this will pave the way for an increase in investments. Turkey's central bank has cut its policy interest rate by 10 percentage points since July to 14%. A Reuters poll last week
Read more →
Trump says doing well with China in putting together trade deal
09.12.2019 20:27
WASHINGTON (Reuters)  President Donald Trump on Monday said the United States is doing well with China in hammering out a trade deal, as the clock ticks toward the levying of possible new tariffs on Chinese imports. U.S. tariffs on several consumer products, including mobile phones and toys, are set to kick in on Dec. 15, but there is hope the
Read more →
Race to Run Bank of Canada Begins With Poloz Bowing Out in June
09.12.2019 20:24
(Bloomberg)  Stephen Poloz’s announcement that he won’t seek a second term as governor of the Bank of Canada kicked off the guessing game on who will succeed him in June. The contest comes as the central bank stubbornly keeps the nation’s benchmark interest rate among the highest of all advanced economies, so one consideration for Prime Minister
Read more →
Italy's TIM agrees deal with DAZN to stream sports
09.12.2019 20:21
MILAN (Reuters)  Telecom Italia (MI:TLIT) (TIM) said on Monday it agreed a deal with digital global sports provider DAZN Group that will enable Italy's biggest phone company to broadcast a wide range of sport events on its own video streaming platform TIM Vision. The tieup follows similar moves by a growing number of telecoms firms hoping
Read more →