Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
CN001532 wrote:I don't need the trendline to actually be drawn on the chart.
Believe me, you will. ;)
You need to keep all code visual to verify that it works, otherwise the whole process becomes hit-and-miss.
My advice would be to adapt the trendline code at http://www.metastocktools.com/MetaStock/2plot.txt
Here is a hint:
[code:1:22c0d7a112]
MetaStock -> Tools -> Indicator Builder -> New
-> Copy and paste formula below.
===============
Trendline - CCI
===============
---8<-----------------------
{ CCI trendline v1.0 }
{ ©Copyright 2005 Jose Silva }
{ For personal use only }
{ http://www.metastocktools.com }
{ User Inputs }
pr:=Input("Indicator Peak/Trough %",
.01,1000,50);
pds:=Input("Indicator periods",1,2600,14);
{ Indicator }
x:=CCI(pds);
{ Indicator peak/troughs }
pk:=PeakBars(1,x,pr)=0;
tr:=TroughBars(1,x,pr)=0;
{ Define trendline events }
time1:=pk;
time2:=tr;
time2:=time2 AND time2<>time1;
val1:=ValueWhen(1,pk,x);
val2:=ValueWhen(1,tr,x);
{ Restrict trendline to last two events}
time1:=
time1 AND Cum(time1)=LastValue(Cum(time1));
time2:=
time2 AND Cum(time2)=LastValue(Cum(time2));
{ Sort trendline events}
t1pds:=LastValue(BarsSince(time1));
t2pds:=LastValue(BarsSince(time2));
x1:=If(t1pds>=t2pds,time1,time2);
x2:=If(t1pds>=t2pds,time2,time1);
y1:=If(t1pds>=t2pds,val1,val2);
y2:=If(t1pds>=t2pds,val2,val1);
{ Fix trendline coordinates}
y1:=ValueWhen(1,x1,y1);
y2:=LastValue(ValueWhen(1,x2,y2));
b1:=LastValue(BarsSince(x1));
b2:=LastValue(BarsSince(x2));
{ Trendline definition}
plot:=y1+BarsSince(x1)*(y2-y1)/(b1-b2+.000001);
{ Un-rem line below to restrict trendline }
{plot:=Ref(Ref(plot,-b2),b2);}
{ Plot in own window }
x;plot
---8<-----------------------
[/code:1:22c0d7a112]
jose '-)
http://www.metastocktools.com
.
|