幅度测幅
a1:=zig(3,n); {设定波段,3为收盘价。要准确判断波段,必须使用这个zig函数}
{N自行设置:一般为2、3、5、8、13、21等等}
a2:=last(a1>ref(a1,1)); {波段上涨天数}
a3:=last(a1<ref(a1,1)); {波段下跌天数}
tt1:=peak(1,N,1); {向前数第一个波峰的值,括号中第一个1表示以最高价作为波峰。这里是用这个波峰值作为这个波段的顶}
bb1:=trough(2,N,1); {向前数第一个波谷的值,括号中的2表示以最低价作为波谷。这里以这个波谷的值作为这个波段的底}
H1:=tt1-(tt1-bb1)*0.1; {设定波段从顶部落下来时,落下的幅度位置,H1是落下10%的位置。以下依此类推}
H2:=tt1-(tt1-bb1)*0.2;
H3:=tt1-(tt1-bb1)*0.3;
H4:=tt1-(tt1-bb1)*0.4;
H5:=tt1-(tt1-bb1)*0.5;
H6:=tt1-(tt1-bb1)*0.6;
H7:=tt1-(tt1-bb1)*0.7;
H8:=tt1-(tt1-bb1)*0.8;
H9:=tt1-(tt1-bb1)*0.9;
H10:=tt1-(tt1-bb1)*1.0;
H11:=tt1-(tt1-bb1)*1.1;
H12:=tt1-(tt1-bb1)*1.2;
H13:=tt1-(tt1-bb1)*1.3;
H14:=tt1-(tt1-bb1)*1.4;
H15:=tt1-(tt1-bb1)*1.5;
L1:=bb1+(tt1-bb1)*0.1; {设定波段从底部涨上去时,上涨的幅度位置,L1是上涨10%的位置。以下依此类推}
L2:=bb1+(tt1-bb1)*0.2;
L3:=bb1+(tt1-bb1)*0.3;
L4:=bb1+(tt1-bb1)*0.4;
L5:=bb1+(tt1-bb1)*0.5;
L6:=bb1+(tt1-bb1)*0.6;
L7:=bb1+(tt1-bb1)*0.7;
L8:=bb1+(tt1-bb1)*0.8;
L9:=bb1+(tt1-bb1)*0.9;
L10:=bb1+(tt1-bb1)*1.0;
L11:=bb1+(tt1-bb1)*1.1;
L12:=bb1+(tt1-bb1)*1.2;
L13:=bb1+(tt1-bb1)*1.3;
L14:=bb1+(tt1-bb1)*1.4;
L15:=bb1+(tt1-bb1)*1.5;
stickline(a3>0,tt1,tt1,8,0),linethick2,colorred; {画波段顶}
stickline(a2>0,bb1,bb1,8,0),linethick2,colorred; {画波段底}
stickline(a3>0,H1,H1,8,0),linethick0,colorFF99CC; {波段下跌,在H1位置画"—"线(图)。以下类推。}
stickline(a3>0,H2,H2,8,0),linethick0,colorFF99CC; {接上行:因为没有在主图画水平线的函数,所以用一系列的“-”来画出水平线}
stickline(a3>0,H3,H3,8,0),linethick0,colorFF99CC;
stickline(a3>0,H4,H4,8,0),linethick0,colorFF99CC;
stickline(a3>0,H5,H5,8,0),linethick0,colorFF99CC;
stickline(a3>0,H6,H6,8,0),linethick0,colorFF99CC;
stickline(a3>0,H7,H7,8,0),linethick0,colorFF99CC;
stickline(a3>0,H8,H8,8,0),linethick0,colorFF99CC;
stickline(a3>0,H9,H9,8,0),linethick0,colorFF99CC;
stickline(a3>0,H10,H10,8,0),linethick0,colorFF99CC;
stickline(a3>0,H11,H11,8,0),linethick0,colorFF99CC;
stickline(a3>0,H12,H12,8,0),linethick0,colorFF99CC;
stickline(a3>0,H13,H13,8,0),linethick0,colorFF99CC;
stickline(a3>0,H14,H14,8,0),linethick0,colorFF99CC;
stickline(a3>0,H15,H15,8,0),linethick0,colorFF99CC;
drawtext(a3=1,H1,'10%'),linethick0,colorFF99CC; {波段下跌,在H1*0.95位置标记"10%"。以下类推。}
drawtext(a3=1,H2,'20%'),linethick0,colorFF99CC; {接上行:在波段下跌第一天处,标注幅度值,看起来一目了然}
drawtext(a3=1,H3,'30%'),linethick0,colorFF99CC;
drawtext(a3=1,H4,'40%'),linethick0,colorFF99CC;
drawtext(a3=1,H5,'50%'),linethick0,colorFF99CC;
drawtext(a3=1,H6,'60%'),linethick0,colorFF99CC;
drawtext(a3=1,H7,'70%'),linethick0,colorFF99CC;
drawtext(a3=1,H8,'80%'),linethick0,colorFF99CC;
drawtext(a3=1,H9,'90%'),linethick0,colorFF99CC;
drawtext(a3=1,H10,'100%'),linethick0,colorFF99CC;
drawtext(a3=1,H11,'110%'),linethick0,colorFF99CC;
drawtext(a3=1,H12,'120%'),linethick0,colorFF99CC;
drawtext(a3=1,H13,'130%'),linethick0,colorFF99CC;
drawtext(a3=1,H14,'140%'),linethick0,colorFF99CC;
drawtext(a3=1,H15,'150%'),linethick0,colorFF99CC;
stickline(a2>0,L1,L1,8,0),linethick0,colorFF99CC; {波段上涨,在L1位置画"—"线(图)。以下类推。}
stickline(a2>0,L2,L2,8,0),linethick0,colorFF99CC;
stickline(a2>0,L3,L3,8,0),linethick0,colorFF99CC;
stickline(a2>0,L4,L4,8,0),linethick0,colorFF99CC;
stickline(a2>0,L5,L5,8,0),linethick0,colorFF99CC;
stickline(a2>0,L6,L6,8,0),linethick0,colorFF99CC;
stickline(a2>0,L7,L7,8,0),linethick0,colorFF99CC;
stickline(a2>0,L8,L8,8,0),linethick0,colorFF99CC;
stickline(a2>0,L9,L9,8,0),linethick0,colorFF99CC;
stickline(a2>0,L10,L10,8,0),linethick0,colorFF99CC;
stickline(a2>0,L11,L11,8,0),linethick0,colorFF99CC;
stickline(a2>0,L12,L12,8,0),linethick0,colorFF99CC;
stickline(a2>0,L13,L13,8,0),linethick0,colorFF99CC;
stickline(a2>0,L14,L14,8,0),linethick0,colorFF99CC;
stickline(a2>0,L15,L15,8,0),linethick0,colorFF99CC;
drawtext(a2=1,L1*1.015,'10%'),linethick0,colorFF99CC; {波段上涨,在L1*1.05位置标记"10%"。以下类推。}
drawtext(a2=1,L2*1.015,'20%'),linethick0,colorFF99CC; {接上行:在波段上涨第一天处,标注幅度值,看起来一目了然}
drawtext(a2=1,L3*1.015,'30%'),linethick0,colorFF99CC;
drawtext(a2=1,L4*1.015,'40%'),linethick0,colorFF99CC;
drawtext(a2=1,L5*1.015,'50%'),linethick0,colorFF99CC;
drawtext(a2=1,L6*1.015,'60%'),linethick0,colorFF99CC;
drawtext(a2=1,L7*1.015,'70%'),linethick0,colorFF99CC;
drawtext(a2=1,L8*1.015,'80%'),linethick0,colorFF99CC;
drawtext(a2=1,L9*1.015,'90%'),linethick0,colorFF99CC;
drawtext(a2=1,L10*1.015,'100%'),linethick0,colorFF99CC;
drawtext(a2=1,L11*1.015,'110%'),linethick0,colorFF99CC;
drawtext(a2=1,L12*1.015,'120%'),linethick0,colorFF99CC;
drawtext(a2=1,L13*1.015,'130%'),linethick0,colorFF99CC;
drawtext(a2=1,L14*1.015,'140%'),linethick0,colorFF99CC;
drawtext(a2=1,L15*1.015,'150%'),linethick0,colorFF99CC;
drawtext(a2=1,bb1*0.995,'下跌'+barslast(a3=1)+'周期'),coloryellow; {波段上涨开始,在底部标记"前一波下跌"的周期数}
drawtext(a3=1,tt1*1.030,'上涨'+barslast(a2=1)+'周期'),coloryellow; {波段下跌开始,在顶部标记"前一波上涨"的周期数};