[PEL] 复制代码
vv:=100;
sth:=ref(h,2)>ref(h,3)&&ref(h,2)>=ref(h,1)&&ref(h,2)>=h;
stl:=ref(l,2)<ref(l,3)&&ref(l,2)<=ref(l,1)&&ref(l,2)<=l;
kk:=hhv(h,todaybar)>ref(max(c,valuewhen(todaybar=1,o)),todaybar)&&exist(stl,todaybar)&&exist(sth,todaybar)&&valuewhen(stl,ref(l,2)<ref(valuewhen(stl,ref(l,2)),1))&&c>valuewhen(sth,ref(h,2));//max bk
dd:=llv(l,todaybar)<ref(min(c,valuewhen(todaybar=1,o)),todaybar)&&exist(stl,todaybar)&&exist(sth,todaybar)&&valuewhen(sth,ref(h,2)>ref(valuewhen(sth,ref(h,2)),1))&&c<valuewhen(stl,ref(l,2));//min sk
kkx:=hhv(h,todaybar)>ref(max(c,valuewhen(todaybar=1,o)),todaybar)&&exist(stl,todaybar)&&exist(sth,todaybar)&&sth&&valuewhen(stl,ref(l,2)<ref(valuewhen(stl,ref(l,2)),1))&&c>ref(valuewhen(sth,ref(h,2)),1);//max bk
ddx:=llv(l,todaybar)<ref(min(c,valuewhen(todaybar=1,o)),todaybar)&&exist(stl,todaybar)&&exist(sth,todaybar)&&stl&&valuewhen(sth,ref(h,2)>ref(valuewhen(sth,ref(h,2)),1))&&c<ref(valuewhen(stl,ref(l,2)),1);//min sk
//kkp:=c<valuewhen(kk||kkx,valuewhen(stl,ref(l,2)))-mindiff&&count(c<valuewhen(kk||kkx,valuewhen(stl,ref(l,2)))-mindiff,barslast(kk||kkx))=1;
//ddp:=c>valuewhen(dd||ddx,valuewhen(sth,ref(h,2)))+mindiff&&count(c>valuewhen(dd||ddx,valuewhen(sth,ref(h,2)))+mindiff,barslast(dd||ddx))=1;
kkp:=c<ref(valuewhen(stl,c),typebar(1,1))-1*mindiff;
ddp:=c>ref(valuewhen(sth,c),typebar(1,3))+1*mindiff;
kd:=kk or kkx;//开多条件
pd:=kkp; //平多反手
mk:=dd or ddx;//开空条件
pk:=ddp; //平空反手
tcon:=time>130000 and time<=185500;//时间大于北京时间9点(金字塔时间130000),小于145500(金字塔时间185500)
//有空头时候才触发反手
if pk and holding<0 and (exitbars>0 or exitbars=-1) then
begin
sellshort(1,holding,market);
buy(tcon,vv,market);
end
buy(kd and holding=0 and tcon,vv,market); //开多信号
//有多头时候才触发反手
if pd and holding>0 and (exitbars>0 or exitbars=-1) then
begin
sell(1,holding,market);
buyshort(tcon,vv,market);
end
buyshort(mk and holding=0 and tcon,vv,market); //开空信号
//止损
zsd:=sell(c<avgenterprice-20*mindiff,holding,market);
zsk:=sellshort(c>avgenterprice+20*mindiff,holding,market);
//止盈
h1:=hhv(h,enterbars+1);//开仓后最高价
l1:=llv(l,enterbars+1);
maxprofit:=if(holding>0,h1-avgenterprice,avgenterprice-l1);//开仓后最大盈利(价差)
currentprofit:=if(holding>0,c-avgenterprice,avgenterprice-c);//当前浮动盈亏(价差)
if maxprofit>=15*mindiff and currentprofit<maxprofit*1 and enterbars>=0 then
begin
zyd:=sell(1,holding,market);
zyk:=sellshort(1,holding,market);
end
//清仓
tq:=60*5;//提前的秒数
abb:=remainingtime(closetime(0))<=tq;
if abb then begin
qcd:=sell(1,holding,market);
qck:=sellshort(1,holding,market);
end