Do you want to get informed about new posts via Email?

LinRegFit

Author: mikael

Creation Date: 2/19/2009 8:32 PM

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.

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.

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.

I don't see any regression lines on the chart. Could you post the entire script if the above is not complete? Thank you.

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:

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

CODE:

Please log in to see this code.

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

Note: I altered LinRegFit to just return the slope.

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.

Hi Eugene,

I don't see anything happening on the chart. Can you re-post the script with corrected cod?

I don't see anything happening on the chart. Can you re-post the script with corrected cod?

squbba: if you want to see a regression line on a chart I think you want this thread:

http://wealth-lab.com/Community/Forum/Posts.aspx?id=gomhZfqEsRslInG2b1zSNe5rZSd5IlLXT0KDK0odA9lwY4TOu4PSXYE9KKyGtbkxUQ/6ouW5dPYXKNtU26gPNaizZrzlGHgyl9V0YdCTLS4=

http://wealth-lab.com/Community/Forum/Posts.aspx?id=gomhZfqEsRslInG2b1zSNe5rZSd5IlLXT0KDK0odA9lwY4TOu4PSXYE9KKyGtbkxUQ/6ouW5dPYXKNtU26gPNaizZrzlGHgyl9V0YdCTLS4=

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

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 ?

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 ?

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