PureBytes Links
Trading Reference Links
|
FWIW, I modified Omega's "TrendLines-Automatic" to draw a channel
instead of a single line.
/Greg Wood
{ *** INDICATOR: TrendChannel(auto) }
{*******************************************************************
Description : This Indicator plots TrendLines-Automatic
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
{ JGW modification: draws channel parallel to the trendline}
Inputs: RHStren(4), RLStren(4), History("Yes"), RHColor("Red"),
RLColor("Green"), RHCColor("DarkRed"), RLCColor("DarkGreen"),
AlrtType("IntraBar");;
input: Channel("Yes");
Variables: RHTLRef(-1), RHTLRef2(-1), RHSet(-1), RHSet2(-1),
RHArrayVal(0), RHColorVar(0), RLColorVar(0), BarsPast(0);
Variables: RLTLRef(-1), RLTLRef2(-1), RLSet(-1),
RLSet2(-1),RLArrayVal(0), RHTLBrk(False), RLTLBrk(False);
var: RHTCRef(-1), RHTCRef2(-1), RHCSet(-1), RHCSet2(-1), RHCColorVar(0),
RLCColorVar(0);
var: RLTCRef(-1), RLTCRef2(-1), RLCSet(-1), RLCSet2(-1);
Arrays: RHDate[10](0), RHTime[10](0), RHVal[10](0), RHBar[10](0);
Arrays: RLDate[10](99999), RLTime[10](99999), RLVal[10](99999),
RLBar[10](99999);
var: offset(0);
If currentbar=1 Then Begin
BarsPast = 10;
RHColorVar = StrColortoNum(RHColor);
RLColorVar = StrColortoNum(RLColor);
RHCColorVar = StrColortoNum(RHCColor);
RLCColorVar = StrColortoNum(RLCColor);
End;
If SwingHighBar(1, High, RHStren, RHStren+1)=RHStren Then Begin
For Value1 = 9 DownTo 0 Begin
RHDate[Value1+1] = RHDate[Value1];
RHTime[Value1+1] = RHTime[Value1];
RHVal[Value1+1] = RHVal[Value1];
RHBar[Value1+1] = RHBar[Value1];
End;
RHDate[0] = Date[RHStren];
RHTime[0] = Time[RHStren];
RHVal[0] = High[RHStren];
RHBar[0] = CurrentBar-RHStren;
For Value22 = 1 To 10 Begin
If RHVal[Value22] > RHVal[0] Then Begin
RHArrayVal = Value22;
Value22 = 11;
End;
End;
If Value22 <> 11 Then Begin
If RHSet >= 0 Then Begin
If UpperStr(History) = "YES" or UpperStr(History) = "Y" Then Begin
If RHTLBrk = False Then begin
RHTLRef2 = TL_SetEnd(RHTLRef, Date,Time, TL_GetValue(RHTLRef, Date,
Time));
if RHTCRef > -1 then RHTCRef2 = TL_SetEnd(RHTCRef, Date,Time,
TL_GetValue(RHTCRef, Date, Time));
end;
RHSet2 = TL_SetExtRight(RHTLRef, False);
if RHTCRef > -1 then RHCSet2 = TL_SetExtRight(RHTCRef, False);
End
Else begin
TL_Delete(RHTLRef);
if RHTCRef > -1 then TL_Delete(RHTCRef);
end;
End;
RHTLBrk = False;
RHTLRef = TL_New(RHDate[RHArrayVal], RHTime[RHArrayVal],
RHVal[RHArrayVal], RHDate[0], RHTime[0], RHVal[0]);
{ calc channel }
if UpperStr(Channel) = "YES" or UpperStr(History) = "Y" then Begin
value81 = 0;
for value80 = RHBar[RHArrayVal] to RHBar[0] Begin
offset = currentbar - value80;
value82 =
absvalue(pnt2line(RHBar[RHArrayVal],RHVal[RHArrayVal],RHBar[0],RHVal[0],value80,low[offset]));
if value81 < value82 then begin
value81 = value82;
value83 = TL_GetValue(RHTLRef,date[offset],time[offset]) -
low[offset];
end;
end;
RHTCRef = TL_New(RHDate[RHArrayVal], RHTime[RHArrayVal],
RHVal[RHArrayVal] - value83,
RHDate[0], RHTime[0], RHVal[0] - value83);
end;
{Error checking To make sure TL was drawn}
If RHTLRef >= 0 Then Begin
RHSet = TL_SetExtRight(RHTLRef, True);
If RHColorVar <> 99 Then
Value14 = TL_SetColor(RHTLRef, RHColorVar);
if RHTCRef > -1 then RHCSet = TL_SetExtRight(RHTCRef, True);
If RHCColorVar <> 99 Then
if RHTCRef > -1 then Value14 = TL_SetColor(RHTCRef, RHCColorVar);
End;
If False Then
Plot1[RHStren](High[RHStren], "RH ");
End;
End;
If SwingLowBar(1, Low, RLStren, RLStren+1) = RLStren Then Begin
For Value1 = 9 DownTo 0 Begin
RLDate[Value1+1] = RLDate[Value1];
RLTime[Value1+1] = RLTime[Value1];
RLVal[Value1+1] = RLVal[Value1];
RLBar[Value1+1] = RLBar[Value1];
End;
RLDate[0] = Date[RLStren];
RLTime[0] = Time[RLStren];
RLVal[0] = Low[RLStren];
RLBar[0] = CurrentBar-RLStren;
For Value22 = 1 To 10 Begin
If RLVal[Value22] < RLVal[0] Then Begin
RLArrayVal = Value22;
Value22 = 11;
End;
End;
If Value22 <> 11 Then Begin
If RLSet >= 0 Then Begin
If (UpperStr(History) = "YES" or UpperStr(History) = "Y") Then
Begin
If RLTLBrk = False Then begin
RLTLRef2 = TL_SetEnd(RLTLRef, Date, Time, TL_GetValue(RLTLRef,
Date, Time));
if RLTCRef > -1 then RLTCRef2 = TL_SetEnd(RLTCRef, Date,Time,
TL_GetValue(RLTCRef, Date, Time));
end;
RLSet2 = TL_SetExtRight(RLTLRef, False);
if RLTCRef > -1 then RLCSet2 = TL_SetExtRight(RLTCRef, False);
End
Else begin
TL_Delete(RLTLRef);
TL_Delete(RLTCRef);
end;
End;
RLTLBrk = False;
RLTLRef = TL_New(RLDate[RLArrayVal], RLTime[RLArrayVal],
RLVal[RLArrayVal], RLDate[0], RLTime[0], RLVal[0]);
{ calc channel }
if UpperStr(Channel) = "YES" or UpperStr(History) = "Y" then Begin
value81 = 0;
for value80 = RLBar[RLArrayVal] to RLBar[0] Begin
offset = currentbar - value80;
value82 =
absvalue(pnt2line(RLBar[RLArrayVal],RLVal[RLArrayVal],RLBar[0],RLVal[0],value80,high[offset]));
if value81 < value82 then begin
value81 = value82;
value83 = TL_GetValue(RLTLRef,date[offset],time[offset]) -
high[offset];
end;
end;
RLTCRef = TL_New(RLDate[RLArrayVal], RLTime[RLArrayVal],
RLVal[RLArrayVal] - value83,
RLDate[0], RLTime[0], RLVal[0] - value83);
end;
{Error checking To make sure TL was drawn}
If RLTLRef >= 0 Then Begin
RLSet = TL_SetExtRight(RLTLRef, True);
If RLColorVar <> 99 Then
Value14 = TL_SetColor(RLTLRef, RLColorVar);
if RLTCRef > -1 then RLCSet = TL_SetExtRight(RLTCRef, True);
If RLCColorVar <> 99 Then
if RLTCRef > -1 then Value14 = TL_SetColor(RLTCRef, RLCColorVar);
End;
If False Then
Plot2[RLStren](Low[RLStren],"RL ");
End;
End;
If RHSet[BarsPast] >= 0 AND Close[BarsPast] Crosses Over
TL_GetValue(RHTLRef, Date[BarsPast], Time[BarsPast]) Then Begin
RHTLRef2 = TL_SetEnd(RHTLRef, Date, Time, TL_GetValue(RHTLRef, Date,
Time));
if RHTCRef > -1 then RHTCRef2 = TL_SetEnd(RHTCRef, Date, Time,
TL_GetValue(RHTCRef, Date, Time));
RHTLBrk = True;
End;
If RLSet[BarsPast] >= 0 AND Close[BarsPast] Crosses Below
TL_GetValue(RLTLRef, Date[BarsPast], Time[BarsPast]) Then Begin
RLTLRef2 = TL_SetEnd(RLTLRef, Date, Time, TL_GetValue(RLTLRef, Date,
Time));
if RLTCRef > -1 then RLTCRef2 = TL_SetEnd(RLTCRef, Date, Time,
TL_GetValue(RLTCRef, Date, Time));
RLTLBrk = True;
End;
If CheckAlert Then Begin
If RHSet >= 0 AND UpperStr(AlrtType) = "ONCLOSE" Then
TL_SetAlert(RHTLRef, 2)
Else
If RHSet >= 0 AND UpperStr(AlrtType) = "INTRABAR" Then
TL_SetAlert(RHTLRef, 1)
Else
If RHSet >= 0 Then
TL_SetAlert(RHTLRef, 0);
If RLSet >= 0 AND UpperStr(AlrtType) = "ONCLOSE" Then
TL_SetAlert(RLTLRef, 2)
Else
If RLSet >= 0 AND UpperStr(AlrtType) = "INTRABAR" Then
TL_SetAlert(RLTLRef, 1)
Else
If RLSet >= 0 Then
TL_SetAlert(RLTLRef, 0);
End;
{*** FUNCTION: PNT2LINE *** }
input: x1(numericsimple), y1(numericsimple),
x2(numericsimple), y2(numericsimple),
x(numericsimple), y(numericsimple);
{ returns the distance from (x,y) to the line formed by (x1,y1) (x2, y2)
}
var: qq(0), m1(0), m2(0);
if x-x2 <> 0 then begin
m1 = (y1-y2) / (x1-x2);
m2 = (y-y2) / (x-x2);
qq = SquareRoot(Square(y-y2)+Square(x-x2));
value1 = qq * sine( arctangent( (m2-m1) / (1 + m1*m2)));
end else
value1 = 0;
pnt2line = value1;
Attachment Converted: "c:\eudora\attach\trendch.ela"
|