Hello friends,
I could use a little help from you AFL / math wizards. I wrote the AFL for generating the equivalent of the AmiBroker Linear Regression study with Standard Error bands. I wrote the following AFL that does a linear regression calc to get an end point and slope from a pivot point. This works fine and matches the center line of a linear regression study hand drawn on the chart. However, the second part which calculates the Standard Error is far from the same as the study. I got the formula from Wikipedia, but perhaps it is not the same as what Tomasz uses. More than likely though, I just do not understand it well enough to write it correctly. If someone is good at this sort of stuff, I would appreciate your taking a look and correcting it.
Thanks, Dennis
// ...lots of setup AFL... // for(i = Start; i < BarCount; i++) // walk forward looking for breakouts { p = C[i]; // i is advanced by one already // calculate the linear regression from the bottom pivot point x1=i-pivb1; // current number of bars from pivot (x1=n in these calcs) xc1=xb1; // number of bars to end of LR calc to project from sy1 += p; sx1 += x1; sxx1 += x1*x1; sxy1 += x1*p; // sums for LR b1[i] = (x1*sxy1 - sx1*sy1)/(x1*sxx1 - sx1*sx1); // slope array a1[i] = sy1/x1 - b1[i]*sx1/x1; // start price array y1 = a1[xc1] + b1[xc1]*x1; // the projected LR from a past point yn1 = a1[i] + b1[i]*x1; // the current LR point // //calculate the std error from the bottom pivot point = sqrt(sum(error^2)/n) / sqrt(n) e1 = p - yn1; // error is diff of price and LR if(x1<=2){se1 = 0;} //init on new pivot se1 += (e1*e1); ser1[i] = sqrt(se1/(x1))/sqrt(x1); // StdErr1 = ser1[i]; // // //...lots more AFL... }
__._,_.___
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
SPONSORED LINKS
__,_._,___
|