extend:=
Input
(
"Extend trendline? [1]Yes, [0]No"
,0,1,1);
plot:=
Input
(
"choose event [1-2] trend"
,1,2,1);
choose:=
Input
(
"plot: [1]Trendline, [2]Event points"
,1,2,1);
time1:=
C
=
HHV
(
C
,21);
time2:=
C
=
LLV
(
C
,21);
time2:=time2
AND
time2<>time1;
dateA:=
Year
()=2006
AND
Month
()=7;
dateA:=
If
(
LastValue
(
Cum
(dateA))=0,
Year
()=
LastValue
(
Year
())-1
AND
Month
()=
LastValue
(
Month
()),dateA);
LoValA:=
Lowest
(
ValueWhen
(1,dateA,
L
));
timeA:=dateA
AND
L
=
LastValue
(LoValA);
dateB:=
Year
()=2006
AND
Month
()=12;
dateB:=
If
(
LastValue
(
Cum
(dateB))=0,
Year
()=
LastValue
(
Year
())
AND
Month
()=
LastValue
(
Month
()),dateB);
LoValB:=
Lowest
(
ValueWhen
(1,dateB,
L
));
timeB:=dateB
AND
L
=
LastValue
(LoValB);
timeB:=timeB
AND
timeB<>timeA;
time1:=
If
(plot=1,time1,timeA);
time2:=
If
(plot=1,time2,timeB);
time1:=time1
AND
Cum
(time1)=
LastValue
(
Cum
(time1));
time2:=time2
AND
Cum
(time2)=
LastValue
(
Cum
(time2));
t1pds:=
LastValue
(
BarsSince
(time1));
t2pds:=
LastValue
(
BarsSince
(time2));
x1:=
If
(t1pds>=t2pds,time1,time2);
x2:=
If
(t1pds>=t2pds,time2,time1);
y1:=
If
(plot=1,
C
,
L
);
y2:=
If
(plot=1,
C
,
L
);
y1:=
ValueWhen
(1,x1,y1);
y2:=
LastValue
(
ValueWhen
(1,x2,y2));
b1:=
LastValue
(
BarsSince
(x1));
b2:=
LastValue
(
BarsSince
(x2));
plot:=
y1+
BarsSince
(x1)*(y2-y1)/Max(b1-b2,.000001);
b2:=
LastValue
(
If
(extend,0,b2));
plot:=
Ref
(
Ref
(plot,-b2),b2);
If
(choose=1,plot,time1+time2)