Linregslope

mastermind007

Well-Known Member
#1
This thread is aimed at understanding one of the Amibroker's built in function LINREGSLOPE

As most of you may already know, this is one of the standard function in many charting softwares and it returns either a single number or a numeric array.

When I look at the help file, it tells me that the LINREGSLOPE function
calculates linear regression line slope from the ARRAY using periods range. The function accepts periods parameter that can be constant as well as time-variant (array).

I hate to admit it but I don't really understand what it means by that. It is bit too cryptic for me or perhaps more simply put, I am unable to exactly understand what is actually being returned. In contrast to this, Microsoft help on the function with same name in some of its library is https://msdn.microsoft.com/en-in/library/ms146085.aspx and is lot more clearer.

A quadratic equation of a line is

y = mx + c

where m is slope and c is a fixed constant value that establishes the distance that the line is away from the x axis.

For sake of simplicity, let me ignore the c for now and therefore, so I can then expect that the LINREGSLOPE function will solve the equation for m = y / x

This means that LINREGSLOPE involves division. But to my surprise, the LinRegSlope function seems to be doing a simple subtraction and that has left me scratching my head. What algebra class had I dozed off?

For example consider a very simple 3 element array named wx that has three consecutive values as.

16740.4
16749.2
16762.3

If I pass this array to LinRegSlope(wx, 2), it will return me array as <Empty>, 8.8, 13.1

8.8 is simply 16749.2 - 16740.4 and 13.1 is simply 16762.3 - 16749.2

You too can try this
Code:
WX[0] = 16740.4 ;
WX[1] = 16749.2; 
WX[2] = 16762.3;
LRS2 = LinRegSlope(WX, 2);
//Values in LRS2 will be {EMPTY}, 8.8, 13.1
If I go for 3 elements, it is simply average of subtracted values.

Code:
LRS 3= LinRegSlope(WX, 3);
//Values in LRS3 will be {EMPTY}, 10.9
10.9 is simply an average of earlier two numbers.
10.9 == (8.8 + 13.1) / 2
 
Last edited: