PureBytes Links
Trading Reference Links
|
Two people have requested on the o-list channel lines (linear regession
?). I posted an indicator of these on the code-list and am posting the
same here to put it into the o-list archive ( http://www.purebytes.com/
).
Massimo Ciarafoni's post on the code-list (26 Oct 2001 10:35:49; CL_Can
anyone explain me this???) in which he adapted Gregory Wood's code
(omega-list: 03 Nov 1998; 24 Jul 1999) to draw parallel trendlines
(channel trendlines) stimulated me to combined two previous post of mine
to give channel trendlines using the regression line. Clyde Lee has
recently posted code for regression channel trendlines on the code-list
(07 Jul 2001 11:35:11; CL_Re: [RT] Clyde's Lineareg.ela). The code
below has three additional features.
1.) The channel can be moved from anywhere on a chart to a new
position by specifying, in the input from the chart, how many bars
ago or ahead (+ or - BarsPlus) from its current bar you want the
new location.
2.) The channel can be move from anywhere on a chart to a new
position by clicking at the new position. Expert Commentary must
be running for this to work. Expert Commentary is accessed either
by the icon with the mortar board hat and pointer on it or from the
Drawing Menu.
3.) Other indicators of volatility, such as SD, can be substituted from
the chart into the input K.
A simple, sample alert is included which can be omitted. Copy the code
into the clipboard and then paste into the powereditor. The code below
is derived from the Omega Research Linear Regression Line Function
Copyright 1999 (as is Clyde Lee's). BarsPlus in my code does not mean
the same thing as in the Omega code. See my next post "LIN REGRESSION
LINE".
YYYMMDD(0) and SlctTime(0) are the right side end points for the
trendlines with the left starting points Len bars ago (back). Both
SlctDate and BarsPlus can be used together or separately. If the center
line is not wanted then just comment out TL1=TL_New(…). Set scaling to
"Same as Symbol". The code also works in RT in minute charts.
In RT, after using the Expert Commentary, the LRL can be kept continusly
updated by moving it to the last bar on the chart and turning off
Expert Commentary.
If only o,h,l or c is use as the input to g=LinearRegValue(c, Len,0); j=
LinearRegValue(c, Len, Len-1); or x=LinearRegSlope(c,Len); then the
variable BK can be added as c[BK] in the above functions and omitted
everywhere else in the code. But if the output of an indicator (placing
the channel on an indicator e.g.) is use as the input to above functions
then leave the code as is.
========================================
Input:Len(15),offset(1), K(AvgTrueRange(30)), YYYMMDD(0),
SlctTime(0),Color(2), BarsPlus(0),Ext(False),Size(0);
Var:LRV(0),LRV1(0),LRV2(0),LRVAgo(0),LRVAgo1(0),LRVAgo2(0),
g0(0),x(0), g(0),j(0),TL(0),TL1(0),TL2(0),
Flag(0),flag1(0),flag2(0), BK(BarsPlus);
g=LinearRegValue(c, Len,0);
j= LinearRegValue(c, Len, Len-1);
x=LinearRegSlope(c,Len); {only used with an alert}
LRV =g + offset*K ; LRVAgo =j + offset*K ;
LRV1 =g; LRVAgo1 =j ;
LRV2 =g - offset*K ; LRVAgo2 =j - offset*K;
If YYYMMDD=0 and AtCommentarybar then begin
Flag = 2;
Value0=1;
End else begin
If Date=YYYMMDD AND (Time=SlctTime OR SlctTime=0) and Flag=0 then begin
Flag = 2;
Value0=1;
end else begin
if LastBarOnChart AND YYYMMDD = 0 AND Flag = 0 Then Begin
Flag = 1;
Value0=1;
end;
end;
End;
If (Flag = 1 OR Flag = 2) and value0=1 Then Begin
value0=2;
TL=TL_New(D[Len-1+BK],T[Len-1+BK],LRVAgo[BK],D[BK],T[BK],LRV[BK]);
TL1=TL_New(D[Len-1+BK],T[Len-1+BK],LRVAgo1[BK],D[BK],T[BK],LRV1[BK]);
TL2=TL_New(D[Len-1+BK],T[Len-1+BK],LRVAgo2[BK],D[BK],T[BK],LRV2[BK]);
TL_SetSize(TL, size);
TL_SetColor(TL, Color);
TL_SetExtRight(TL, Ext);
TL_SetSize(TL1, size);
TL_SetColor(TL1, Color);
TL_SetExtRight(TL1, Ext);
TL_SetSize(TL2, size);
TL_SetColor(TL2, Color);
TL_SetExtRight(TL2, Ext);
End;
If Flag = 1 Then Begin
TL_SetBegin(TL, D[Len-1+ BK],T[Len-1+ BK], LRVAgo[BK]);
TL_SetEnd(TL, D[BK],T[BK], LRV[BK]);
TL_SetBegin(TL1, D[Len-1+ BK],T[Len-1+ BK], LRVAgo1[BK]);
TL_SetEnd(TL1, D[BK],T[BK], LRV1[BK]);
TL_SetBegin(TL2, D[Len-1+ BK],T[Len-1+ BK], LRVAgo2[BK]);
TL_SetEnd(TL2, D[BK],T[BK], LRV2[BK]);
End;
If CheckAlert then
if x<0 and C crosses over LRV then alert=true;
If CheckAlert then
if x>0 and C crosses under LRV2 then alert=true;
if false then plot1(flag2,""); {only needed for TS4}
|