P:=8;
XS1:=0;
说明:=1;
趋势:=zig(3,P);
↑:=TROUGHBARS(3,P,1),NODRAW;
↓:=PEAKBARS(3,P,1),NODRAW;
低:=IF(↑=0,C,IF(↓<↑,TROUGH(3,P,1),REF(TROUGH(3,P,1),1))),NODRAW;
高:=IF(↓=0,C,IF(↑<↓,PEAK(3,P,1),REF(PEAK(3,P,1),1))),NODRAW;
涨%:=IF(↑<↓,(C/低-1)*100,REF((C/低-1)*100,↓)),COLORRED,NODRAW;
跌%:=IF(↓<↑,(C/高-1)*100,REF((C/高-1)*100,↑)),COLORGREEN,NODRAW;
上:IF(趋势>REF(趋势,1),趋势,DRAWNULL),COLORRED,LINETHICK1;
下:IF(趋势<REF(趋势,1),趋势,DRAWNULL),COLORGREEN,LINETHICK1;
买入条件:=TFILTER(↑=0,↓=0,1);
卖出条件:=TFILTER(↓=0,↑=0,0);
买入价:=IF(买入条件,C,DRAWNULL);
卖出价:=IF(卖出条件,C,DRAWNULL);
DRAWICON(买入条件,L*0.98,1);
DRAWICON(卖出条件,H*1.02,2);
DRAWNUMBER(买入条件,L*0.96,买入价),COLORRED;
DRAWNUMBER(卖出条件,H*1.04,卖出价),COLORGREEN;
DRAWNUMBER(卖出条件,H*1.06,(C/REF(C,BArslAST(买入条件))-1)*100),COLORYELLOW;
成交收益:=IF(卖出条件,(C/REF(C,BARSLAST(买入条件))-1)*100*0.994,DRAWNULL);
年交易收益:=SUM(成交收益,250),NODRAW;
年成交数:=IF(ISLASTBAR,SUM(卖出条件,250),DRAWNULL),NODRAW;
平均每次收益:=年交易收益/年成交数,NODRAW;
DRAWTEXT_FIX(XS1=0,0.00,0.00,0,STRCAT('年交易次数: ',CON2STR(年成交数,0))),COLORLIRED;
DRAWTEXT_FIX(XS1=0,0.00,0.05,0,STRCAT('年交易收益: ',CON2STR(年交易收益,2))),COLORLIRED;
DRAWTEXT_FIX(XS1=0,0.00,0.10,0,STRCAT('平均每次收益: ',CON2STR(平均每次收益,2))),COLORLIRED;
DRAWTEXT_FIX(说明=1,0.00,0.15,0,'红箭头是买入信号,红数字是买入参考价'),COLORRED;
DRAWTEXT_FIX(说明=1,0.00,0.20,0,'绿箭头是卖出信号,绿数字是卖出参考价'),COLORGREEN;
DRAWTEXT_FIX(说明=1,0.00,0.25,0,'黄色数字是盈亏百分比'),COLORYELLOW;
LL:=LLV(L,250);
HH:=HHV(H,250);
A:(CONST(C)-CONST(LL))/CONST(HH)*100,NODRAW;
STICKLINE(CURRBARSCOUNT=120,LL,HH,3,-1),COLORYELLOW;
STICKLINE(CURRBARSCOUNT=120,LL,CONST(C),2,0),COLORMAGENTA;
AA:= STRCAT(STRCAT('涨幅比:',VAR2STR(A,2)),'﹪');
DRAWTEXT(CURRBARSCOUNT=145,CONST(C),AA)COLORYELLOW;