PureBytes Links
Trading Reference Links
|
HB,
I can't take credit creating anything, except cutting and pasting
some things together.
"ind" is a linear regression formula I ran across on a Metastock list
and "LinReg" I think I found here. I just put them together and
translated them into AFL.
Basically, in it's current form, it's a good visual tool, but it
takes current values to plot backwards. As new bars are made, the
angle changes and the whole thing moves forward.
Maybe some of the good math guy's on the board can figure out how
to "move it back" and project values forward. Of course, there are
likely more elegant ways to do all this.
The "LinReg" by itself seems like a useful indicator. It matches the
Metastock linear regression indicator closely, especially with larger
period values. Try a plot of it alone.
Play around with "Dist" to get your parallel lines.
Dist=2*LastValue(ATR(Period-1));// distance from regression
or
Dist=1;// distance from regression
or
whatever.
Good Luck,
Ed
--- In amibroker@xxxx, "hmab1" <hbahlool0542@xxxx> wrote:
>
> Hello Ed,
>
> Wow ! That's amazing.
>
> However, in order to learn, I would prefer to understand the
concept
> behind how you created this AFL.
>
> Could you provide some comments for your code.
>
> I'm asking because I want to modify this code to be able to display
> the line & channels starting from a certain day and ending on a
> certain day (not necessarily today). So, there would be two
> variables (Period & Daysback) or (startdate & enddate).
>
> Also, I want to modify the "dist" variable so that it is equal to
the
> the max absolute difference between the regression line and the
price
> array in that period.
>
> Thanks again,
> HB
>
> --- In amibroker@xxxx, "Sharps_45_70" <sharps_45_70@xxxx> wrote:
> > HB,
> >
> > Try this.
> >
> > Ed
> >
> > ///////////////////////////////////////////////////////
> > Period=40;
> > price=A;// choose price array
> >
> >
> > LinReg=( Period * Sum( Cum( 1 ) * price,Period ) -
> > Sum( Cum( 1 ),Period) * Sum( price,Period) ) /
> > (Period * Sum(Cum( 1 )^2,Period ) -
> > Sum( Cum( 1 ),Period )^2 ) * Cum( 1 ) + (MA(price,Period) -
> > MA( Cum(1 ),Period) * (Period * Sum( Cum( 1 ) * price,Period) -
> > Sum( Cum( 1 ),Period ) * Sum( price,Period) ) / (Period *
> > Sum( Cum(1 )^2 ,Period) - Sum( Cum( 1 ),Period )^2 ) );
> >
> > ind=(LastValue(LinReg)-(LastValue(LinRegSlope(price,Period))*
> > (LastValue(Cum(1))-Cum(1))))+Ref(price,(0-(LastValue(Cum(1))-
> > Period)))-Ref(price,(0-(LastValue(Cum(1))-Period)));
> >
> > Dist=ind*.05;// distance from regression
> >
> > Plot( price, "Price", 1, 64);
> > Plot( ind, "Regression", 5, 1);
> > Plot( ind+Dist, "+Line", 6, 1);
> > Plot( ind-Dist, "-Line", 6, 1);
> > /////////////////////////////////////////////////////
|