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

Re: [amibroker] Re: How to enhance Linear Regression Channel Code to plot two previous days



PureBytes Links

Trading Reference Links

hi,

The code Herman posted few days back, see subject: "AFL for Linear Regression Study"  does that, see parameter window "Extend"

I also wrote some code few years back (see below). "Future" points are displayed using styleDots,
 
rgds, Ed
 
 
per = 20;
fut =
5
;
//mm = (H + L + C) / 3;

mm =
C
;

x =
Cum(1
);
lastx = LastValue(x);
selv =
SelectedValue
(x);

aaa =
LinRegIntercept
(mm, per);
bbb =
LinRegSlope
(mm, per);

daa =
SelectedValue(ValueWhen(x, aaa, 1
));
dbb =
SelectedValue(ValueWhen(x, bbb, 1
));

xx =
IIf(x > selv - per AND x <= selv, x - (selv - per),Null
);
yy = daa + dbb * xx;

fxx =
IIf(x > selv AND x <= selv + fut, x - (selv - per),Null
);
fyy = daa + dbb * fxx;

wd =
SelectedValue(StDev
(mm,per));

SetChartOptions(0, chartShowDates
);
Plot(yy, "LinReg", colorBlue, 1
);
Plot(yy + wd, "Upper Boundary", colorRed, 1
);
Plot(yy - wd, "Lower Boundary", colorBrightGreen, 1
);

// plot into future

Plot(fyy, "LinReg", colorBlue ,styleDots | styleNoLine
);
Plot(fyy + wd, "Upper Boundary", colorRed ,styleDots | styleNoLine
);
Plot(fyy - wd, "Lower Boundary", colorBrightGreen ,styleDots | styleNoLine
);

Plot(C,"",colorWhite,64);




----- Original Message -----
From: tradinghumble
To: amibroker@xxxxxxxxxxxxxxx
Sent: Tuesday, July 29, 2008 4:04 PM
Subject: [amibroker] Re: How to enhance Linear Regression Channel Code to plot two previous days


Hi Ara, I think you missed posting the code in your message - you
stopped at "The ending point:"

thanks for your help.

--- In amibroker@xxxxxxxxxxxxxxx, "Ara Kaloustian" <ara1@xxx> wrote:
>
> You need two pieces of information to find the linear regression:
> 1. Last point of interest : LinearReg( ARRAY, periods )
> 2. First point of interest: LinRegIntercept( ARRAY, periods )
>
> To find LR for 2 days ago use Ref(Close,-2) for Array.
>
> Then use LineArray function to draw the line between the two points.
>
> To get the channel, use the standard error code in the code below.
> To extend the channel to today, use the proper parameter on the
linearray
> function
>
> I have not tested this, so the channel may draw to the current day
without
> extending.. I am not sure
>
> The ending point:
> ----- Original Message -----
> From: "tradinghumble" <sharp2be@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Monday, July 28, 2008 9:42 PM
> Subject: [amibroker] How to enhance Linear Regression Channel Code
to plot
> two previous days
>
>
> > Hello, I've seen this nice piece of code that plots linear regression
> > code and was wondering if anyone could help me with a hint on how to
> > plot the channel two days ago and extend it into today. I've already
> > fried my brain, can't get it... thanks in advance.
> >
> > SetBarsRequired(100000,0);
> > bar = BarIndex();
> > islastbar = bar == BarCount -10;
> > isfirstbar = bar == BarCount - 100;
> > firstbar = LastValue( ValueWhen( isfirstbar, bar ) );
> > lastbar = LastValue( ValueWhen( islastbar, bar ) );
> > al = LastValue( ValueWhen( islastbar, LinRegSlope( C, Lastbar -
> > firstbar + 1 ) ) );
> > bl = LastValue( ValueWhen( islastbar, LinRegIntercept( C, Lastbar -
> > firstbar + 1 ) ) );
> > Lr = al * ( BarIndex() - firstbar ) + bl;
> > Lr = IIf( bar = firstbar AND bar <= lastbar , Lr, Null );
> > se = StdErr(C,Lastbar - firstbar);
> > se = LastValue( ValueWhen( islastbar, StdErr( C, Lastbar - firstbar +
> > 1 ) ) );
> > upper = Lr + se;
> > Lower = Lr - se;
> >
> > Plot(Lr, "lr", colorYellow, styleThick );
> > Plot(upper, "upper", colorGreen, styleThick );
> > Plot(Lower, "lower", colorRed, styleThick );
> > SetBarFillColor( IIf( C O, colorBrightGreen, colorRed ) );
> > Plot(C, "C", colorWhite, styleCandle );
> > Title = "bar= " + bar + " firstbar= " + firstbar + " lastbar= " +
> > lastbar+ " se= "+ se;
> >
> >
> >
> > ------------------------------------
> >
> > 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
> > Yahoo! Groups Links
> >
> >
> >
>


__._,_.___

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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___