I want to use this routine to get the slope and therefore the trend. I thought I had this working in my program, but the slope is always negative?!? Or always positive if X goes from 10 down to 1. I'm using the daily S&P500 as the index. I've checked sigma slope and slope (what's the difference?). The data works back from the date shown.
11/15/07 downtrend
i=23323 X=1 MClose[i]=1451.15
i=23297 X=2 MClose[i]=1470.58
i=23271 X=3 MClose[i]=1481.05
i=23245 X=4 MClose[i]=1439.1801
i=23219 X=5 MClose[i]=1453.7
i=23193 X=6 MClose[i]=1474.77
i=23167 X=7 MClose[i]=1475.62
i=23141 X=8 MClose[i]=1520.27
i=23115 X=9 MClose[i]=1502.17
i=23089 X=10 MClose[i]=1509.65
Slope=-0.0980010101009887
11/13/2006 uptrend
i=16764 X=1 MClose[i]=1384.42
i=16738 X=2 MClose[i]=1380.9
i=16712 X=3 MClose[i]=1378.33
i=16686 X=4 MClose[i]=1385.72
i=16660 X=5 MClose[i]=1382.84
i=16634 X=6 MClose[i]=1379.78
i=16608 X=7 MClose[i]=1367.34
i=16582 X=8 MClose[i]=1367.8101
i=16556 X=9 MClose[i]=1377.9399
i=16530 X=10 MClose[i]=1377.9301
Slope=-3.40190969696967
11/11/04 uptrend
i=3854 X=1 MClose[i]=1173.48
i=3828 X=2 MClose[i]=1162.91
i=3802 X=3 MClose[i]=1164.08
i=3776 X=4 MClose[i]=1164.89
i=3750 X=5 MClose[i]=1161.67
i=3724 X=6 MClose[i]=1143.2
i=3698 X=7 MClose[i]=1130.54
i=3672 X=8 MClose[i]=1130.51
i=3646 X=9 MClose[i]=1130.2
i=3620 X=10 MClose[i]=1127.4399
Slope=-5.65273272727273
CODE:
Please log in to see this code.
Note: I altered LinRegFit to just return the slope.