ggg:=ref(hhv(h,3),1);
//三周期高点
ddd:=ref(llv(l,3),1);
//三周期低点
b:=cross(c,ggg) and ref(barslast(cross(c,ggg)),1)>ref(barslast(cross(ddd,c)),1);
//开多条件
s:=cross(ddd,c) and ref(barslast(cross(c,ggg)),1)<ref(barslast(cross(ddd,c)),1);
//开空条件
//DRAWICON(b ,0 ,6 ,0 );
//DRAWICON(s ,0 ,7 ,0 );
btime:=barslast(b);
//上次开多信号到现在周期数
stime:=barslast(s);
//上次开空信号到现在周期数
bpb:=l<ddd and c>ddd and btime>0 and btime<stime;
//持有多仓时,同一K线平仓再开多仓
sps:=h>ggg and c<ggg and stime>0 and stime<btime;
//持有空仓时,同一K线平仓再开空仓
batr:=ref(c,btime)-ref(l,btime+2);
//上次开多时,止损距离点数
satr:=ref(h,stime+2)-ref(c,stime);
//上次开空时,止损距离点数
//每日盈利与开仓时的止损空间的比例
ylbl:=if(btime<stime,
if(btime=0,(ref(c,1)-ggg)/satr,if(bpb=1,(ddd-ref(c,1))/batr,(c-ref(c,1))/batr)),
//持有多仓时候,每天的盈利幅度,区别是否当天平多再开多
if(stime=0,(ddd-ref(c,1))/batr,if(sps=1,(ref(c,1)-ggg)/satr,(ref(c,1)-c)/satr))
//持有空仓时候,每天的盈利幅度,区别是否当天平多再开多
);
//每个周期盈利比例
//按单利累加计算资金净值数
//盈利曲线:sum(ylbl,0),NODRAW;
zj:=1;
for i=0 to 10 DO
begin
zj=ref(zj,1)*ylbl;
end
盈利曲线2:zj;