The regression slope is given by the code found in the LinReg indicator:
double sumX = (double) Period * (Period - 1) * 0.5; double divisor = sumX * sumX - (double) Period * Period * (Period - 1) * (2 * Period - 1) / 6; double sumXY = 0; for (int count = 0; count < Period && CurrentBar - count >= 0; count++) sumXY += count * Input[count]; double slope = ((double)Period * sumXY - sumX * SUM(Input, (int)Period)[0]) / divisor;
There isn't source code available for the built-in Slope() method, so I can't debug it. There are faster algorithms, by the way, that don't require execution of a loop on each bar. For example, with Mark Simms and Bob Fulks, we developed a super-fast calculation that reproduces the linear regression slope exactly without executing a loop on each bar. My TradeStation code is here.
If the Slope() method is calculating something other than the slope of a regression line, the documentation should say what that is.
-Alex
Comment