LinRegFit
Author: mikael
Creation Date: 2/19/2009 8:32 PM
profile picture

mikael

#1
For your viewing pleasure.

CODE:
Please log in to see this code.
profile picture

TrendCatcher

#2
Hi Mikael,
I don't see anything on the chart. Is there any error in the script?
profile picture

DrKoch

#3
mikael,
you translated my WL4 study "LinRegFit" to WL5. Good.
Please give credits to the original author (or at least mention where you take your ideas from)

TrendCatcher,
LinRegFit is just a helper function which can do a linear regression on a collection of points, very helpful sometimes.
profile picture

TrendCatcher

#4
Hi DrKoch,
I don't see any regression lines on the chart. Could you post the entire script if the above is not complete? Thank you.
profile picture

mikael

#5
Sorry DrKoch. I wasn't claiming originality just providing the code. So, yes refined and translated from Dr Koch's original Object Pascal code into C#. And originally I think from "Numerical Recipes in C". That do?

BTW you're going to need this class for the above:

CODE:
Please log in to see this code.
profile picture

jimcrist

#6
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.
profile picture

jimcrist

#7
Nevermind, I guess it's working...
profile picture

sgubba

#8
Hi Eugene,
I don't see anything happening on the chart. Can you re-post the script with corrected cod?
profile picture

Eugene

#9
Why not ask its author? Neither it's my code nor I have the interest to follow it.
profile picture

sgubba

#10
:)
profile picture

jimcrist

#11
profile picture

sgubba

#12
Jimcrist,
Thank you very much.
profile picture

Eugene

#13
In addition, you may want to take a look at TSF (Time Series Forecast) in Community.Indicators.
profile picture

sgubba

#14
Thank you Eugene.
profile picture

zanek

#15
Eugene,

I tried to add : "using Community.Indicators;"

to my code but it says the type or namespace couldnt be found. What do I need to do so that that namespace can be found ?


profile picture

Eugene

#16
You need to install the Community.Indicators library first --> Extensions