Slope, in mathematics, is dy/dx - where dx is the difference in x between two points and dy is the difference in y. So - if x stays constant, the slope is 0. If the line is vertical (dx=0) then the slope is infinite. (On a coordinate system where X and Y are equivalent, the slope would be the tangent of the angle of the slope).
The problem, of course, is - what are the units of dx (dy, I presume, is price). Because obviously the slope itself, unless it is exactly 0, is pretty meaningless if the units of x are arbitrary and unrelated to the units of y (as is the case in stock charts).
Thus, the only way you can use slope in stock charts is to compare two of them.
To find an approximation of a slope of 20 EMA, or any other function, at point X (let's say X is candle number) is to take its value at X+1, its value at X-1, and divide it by 2 (X+1)-(X-1). The reason it is an approximation and not a real slope is because the chart is not a curve but a set of segments, and the slope at the points where the segments connect is, strictly mathematically, indeterminate.
Another way to find a slope would be to fit a Bezier curve or a spline through a set of points surrounding point X, do symbolic differentiation of the curve function, and find its value at point X. Not really feasible. Too complicated.
A third way would be to do a linear regression slope calculation on let's say last 5 points and presume that the slope is the slope of the regression line.
or, in advanced code in paintbars or scanner (presuming that EMA is the variable representing the value of the indicator)
.fctbNone{ color:#000000; }
.fctbStyle4{ color:#0000ff; }
.fctbStyle3{ color:#000000; } double sumxy = 0;
double sumxx = 0;
double averagex = 2;
double averagey = Average(5,EMA);
for (int x=0;x<5;x++)
{
sumxx += (x-averagex)*(x-averagex);
sumxy += (x-averagex)*(EMA[x]-averagey);
}
var Slope = sumxy/sumxx;
Which reminds me - I really should find a way to have the MT looping functions to incorporate the n variable. Right now there is no way to do that, so I had to do the actual loop.