[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Metastockusers] need accurate Linear Regression code



PureBytes Links

Trading Reference Links

I need the Linear Regression Indicator & Linear Regression Slope 
formulae.

The code I've been using (from memory, similar to Corey's code?) gives 
good matching plots with MS v8.01, until I begin using shorter 
periods.


Linear Regression Indicator formula
===================================

---8<------------------------------

pds:=Input("LinReg periods)",2,2520,14);
x:=Input("use Open=1, High=2, Low=3, Close=4, Volume=5",1,5,4);
x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=4,C,V))));

y:=pds*Sum(Cum(1)*x,pds)
 -Sum(Cum(1),pds)*Sum(x,pds);
z:=pds*Sum(Pwr(Cum(1),2),pds)
 -Pwr(Sum(Cum(1),pds),2);
LR:=y/z*Cum(1)-y/z*Mov(Cum(1),pds,S)+Mov(x,pds,S);

LR

---8<------------------------------


Linear Regression Slope formula
===============================

---8<------------------------------

pds:=Input("LinRegSlope periods",2,252,21);
x:=Input("Use Open=1, High=2, Low=3, Close=4, Volume=5",1,5,4);
x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=4,C,V))));

y:=pds*Sum(Cum(1)*x,pds)
 -Sum(Cum(1),pds)*Sum(x,pds);
z:=pds*Sum(Pwr(Cum(1),2),pds)
 -Pwr(Sum(Cum(1),pds),2);

y/z

---8<------------------------------


Using the code above with a 2-period LinReg should match the price 
plot exactly, but it doesn't.

Anyone help, please?

jose '-)



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Save up to 80% on top-quality inkjet cartridges and get your order fast!
FREE shipping on orders $50 or more to the US & Canada. Shop at Myinks.com!
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/v2G7ND/KfUGAA/ySSFAA/zMEolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
Metastockusers-unsubscribe@xxxxxxxxxxx

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/