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

Trendline



PureBytes Links

Trading Reference Links


A better form
 
/*TRENDLINE*/
maxgraph=8;graph0 = 
c;graph0style=64;graph0barcolor=1;x = cum(1);per = 
3;s1=l;s11=h;RANKt=1;RANKp=1;pS = troughBars( s1,per, 1 ) == 
0;endt= lastvalue(ValueWhen( pS, x, RANKt ));/*trough time*/pR = 
PEAKBars( s11, per, 1 ) == 
0;                    
endt1= lastvalue(ValueWhen( pR, x, RANKp ));/*peak 
time*/dt=iif(endt-endt1>0,endt-endt1,endt1-endt);     
endS = lastvalue(ValueWhen( pS, s1, RANKt ) );/*trough value*/endR = 
lastvalue(ValueWhen( pR, s11, RANKp ) );/*peak 
value*/aS=iif(endt-endt1>0,(endS-endR)/dt,-(endS-endR)/dt);/*slope*/bS=iif(endt-endt1>0,endS,endR);/*beta*/TR=aS*(x-max(endt,endt1))+bS;/*TRENDLINE 
EQUATION*/graph1 = 
iif(x>min(endt,endt1)-10,tr,-1e10);graph3=zig(s11,per);graph3barcolor=9;graph4=zig(s1,per);graph4barcolor=0;
 
RANKt and RANKp is the rank of the trough, 
respectively the peak
counting from the end of data. For 
example
RANKt=2, RANKp=3 means the second trough and the 
third peak.
For verification, I added the respective zig 
functions.
Hoping now that wrapping will not mix troughs and 
peaks
Dimitris Tsokakis