MetaStock™ Zone Forum & FAQ Artykuły Linki Elliott Waves EasyLanguage™ Zone

 A B C D E F G H I J K L M N O P R S T U V W Y Z #

Linear Regression Trendline & Channels by Jose Silva
Linear Regression Trendline with Standard Deviation/Error Channels/Bands, date-adjustable.

Linear Regression Trendline & Channels

{ Linear Regression Trendline & Channels v4.0 }
{ (c) Copyright 2004-2005 Jose Silva }
{ For personal use only }
{ http://www.metastocktools.com }

{ User Inputs }
pds:=Input("Linear Regression Trendline periods",2,2520,63);
multi:=Input("Standard Deviations(+) / Errors(-)",-100,100,2);
EnDay:=Input("end Day",1,31,31);
EnMnth:=Input("end Month",1,12,12);
EnYear:=Input("end Year",1800,2200,2010);
x:=Input("use: Open=1 Hi=2 Lo=3 Close=4 WghtCl=5 Volume=6",1,6,4);
x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,WC(),If(x=6,V,C)))));

{ End date point }
end:=Year()>EnYear
OR (Year()=EnYear AND (Month()>EnMnth
OR Month()=EnMnth AND DayOfMonth()>=EnDay));
end:=If(LastValue(Cum(Ref(end,pds)))=0,
LastValue(Cum(1))=Cum(1),end);

{ Linear Regression Trend/Slope end-points }
lastValLRI:=LastValue(Highest(
If(end,LinearReg(x,pds),0)));
lastValLRS:=LastValue(Highest(
If(end,LinRegSlope(x,pds),-10000)));
-Highest(If(end,Cum(1),0)));

{ Rem next line to extend plot to end of chart }

{ Lin Reg Trendline }
LR:=lastValLRI-lastValLRS*countback;
LRT:=Ref(Ref(LR,-restrict),restrict);

{ Lin Reg StdDev/StdError channels }
bandType:=If(multi>=0,Stdev(x,pds),STE(x,pds));
diff:=ValueWhen(1,Cum(IsDefined(LRT))=1,
bandType*Abs(multi));
upLR:=LRT+diff;
lwLR:=LRT-diff;

{ Plot on price chart }
upLR;lwLR;LRT

Source / From: TOP
http://www.metastocktools.com

Equis and MetaStock® and MetaStock Professional® are registered trademarks of Equis International. Achelis Binary Wave®, The DownLoader®,
Expert Advisor®, OptionScope®, Quotecenter® and Smart Charts® are trademarks of Equis International, a Thomson Reuters company.