[PEL] 复制代码
valuewhen(todaybar=1,open);
n1:=todaybar;
dm:=4-intpart(log(c));
结算价:rounds(if(sum(vol,n1)=0,c,sum(c*vol,n1)/sum(vol,n1)),2+dm);
partline(close>结算价,结算价),linethick1,colorff;
partline(close<结算价,结算价),linethick1,colorff0000;
hh:=hhv(close,n);
ll:=llv(close,n);
hh1:=barslast((hh>ref(hh,1)));
ll1:=barslast((ll<ref(ll,1)));
a:=ifelse((hh1 < ll1),1,ifelse((hh1 > ll1),-1,0));
aa:ifelse(a>=0,ll,hh),dot,coloryellow;
partline(close>aa,aa),linethick2,colorff;
partline(close<aa,aa),linethick2,colorff0000;
ma6:=ema(close,60);
partline(ma6>ref(ma6,1), ma6,colorred);
partline(ma6<ref(ma6,1) , ma6,colorblue);
手数:=ss;
//交易条件
开多条件:=cross(ll1,hh1)&&结算价>ref(结算价,1);
平多条件:=cross(hh1,ll1);
开空条件:=cross(hh1,ll1)&&结算价<ref(结算价,1);
平空条件:=cross(ll1,hh1);
//交易系统
平空:sellshort(平空条件 and holding<0,手数,limitr,c);
平多:sell(平多条件 and holding>0,手数,limitr,c);
开空:buyshort(开空条件 and holding>=0 and time<>closetime(0),手数,limitr,c);
开多:buy(开多条件 and holding<=0 and time<>closetime(0),手数,limitr,c);
//注意先平后开原则
if c-avgenterprice>=6*mindiff then
begin
多止盈:sell(1,holding,market);
end
if avgenterprice-c>=6*mindiff then
begin
空止盈:sellshort(1,holding,market);
end
if avgenterprice-c>=10*mindiff then
begin
多止损:sell(1,holding,market);
end
if c-avgenterprice>=10*mindiff then
begin
空止损:sellshort(1,holding,market);
end
if (time=closetime(0) and not(islastbar)) or (islastbar and remainingtime(closetime(0))<=60) then
begin
收盘平空:sellshort(1,holding,market);
收盘平多:sell(1,holding,market);
end