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

Re: Parallel lines for regression channels ?



PureBytes Links

Trading Reference Links

HB,

Try working off this formula from the AFL library.

http://www.amibroker.com/library/formula.php?id=106

Ed


--- In amibroker@xxxx, "HB" <hbahlool0542@xxxx> wrote:
> Ok, I've been trying to build the 40-day linear regression line 
(starting from today, going back 40 days) and I can't even seem to do 
that.
> 
> First, some basic math:
> 
> linear line: y = mx + b where m is the slope, b is the intercept, 
and x is the bar #
> 
> LRline = Slope * (bar #) + Intercept
> 
> Note: Any time I write "Summation", it is the sum of the variable 
for i = 1 to N, where N is the period
> 
> Slope = [ N*(Summation(X*Y)) - Summation(X) * Summation(Y) ] / [N * 
Summation (X^2) - (Summation(X))^2]
> OR
> Slope = [Summation ((X-MeanX)*(Y-MeanY))] / [Summation((X-MeanX)^2)]
> 
> Intercept = [Summation(Y) - Slope * Summation(X)] / N
> OR
> Intercept = MeanY - Slope * MeanX
> 
> Based on that, here's the AFL I've implemented so far. Someone 
please correct what I'm doing wrong !
> 
> // Raff Regression Channels (at least the beginning of it :)
> 
> periods = 40;
> DaysBack = 0;
> 
> // Compute the number of bars in datafile, this section was 
developed by Frank Snay
> RABars = 0; //initialize
> TotalBars = Cum(1); //how many bars in database
> FinalBar = LastValue(TotalBars);//number value of last bar
> EndDay = FinalBar - DaysBack;//for other than 0 DaysBack
> StartDay = EndDay - periods+1;//starting point for line
> Master1 = IIf(TotalBars >= StartDay AND TotalBars <= 
EndDay,1,0);//defined period
> RABars = IIf(Master1,Ref(RABars,-1)+1,0); // daily counter in 
defined period
> RABarKntr = IIf(Master1,Sum(RABars,periods),0); //Sum of daily 
counts
> 
> // Calculate LRLine formula components
> SumX = Sum (RABars, periods);
> SumY = Sum(C, periods);
> SumXY = Sum (C * RABars, periods) ;
> SumXX = Sum (RABars * RABars, periods);
> 
> n = periods;
> 
> Slope = (n * SumXY - SumX * SumY) / (n * SumXX - SumX * SumX );
> Intercept = (SumY - Slope * SumX) / n;
> 
> /*
> // Other calculation method which yields a different result ?!
> SumX = Sum (RABars, periods);
> SumY = Sum(C, periods);
> SumXY = Sum (C * RABars, periods) ;
> SumXX = Sum (RABars * RABars, periods);
> MeanX = SumX/periods;
> MeanY = SumY/periods;
> 
> Slope = Sum((RABars-MeanX)*(C-MeanY), periods);
> Intercept = MeanY - slope * MeanX;
> */
> 
> // Linear Regression Line
> LRLine = Slope * RABars + Intercept; 
> LRLine = IIf(RABarKntr >= 1, LRLine,-1e10);
> 
> // Graph the output
> MaxGraph=2;
> Graph0 = Close; Graph0Style = 1; Graph0Color =1;
> Graph1 =LRLine; Graph1Style = 1;
> 
> //END
> 
> ----- Original Message ----- 
> From: hmab1 
> To: amibroker@xxxx 
> Sent: Tuesday, July 23, 2002 7:07 PM
> Subject: [amibroker] Parallel lines for regression channels ?
> 
> 
> 
> Hello,
> 
> Is it possible in AFL to contruct parallel lines on either side 
of a 
> linear regression line ?
> 
> I'm trying to build a linear regression channels indicator.
> 
> The central line would be the linear regression line. The upper 
and 
> lower channel lines are placed equidistant from the center line 
and 
> parallel to it. The distance between the central line and the 
upper 
> line would be equal to greatest distance between the central line 
and 
> the highest value. The distance between the central line and the 
> lower line would be equal to greatest distance between the 
central 
> line and the lowest value.
> 
> I've been racking my brain, reading through the various AFL 
> functions, and searching this group !! Is this even possible ?
> 
> Inputs would be the start date, end date, and variable array 
(e.g. 
> Close).
> 
> Thanks,
> HB
> 
> 
> 
> Yahoo! Groups Sponsor 
> ADVERTISEMENT
> 
> 
> 
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of 
Service.