[PEL] 复制代码
input:s(5,1,100,1),p(10,1,100,1),m(5,1,100,1);
diff:ema(close,s) - ema(close,p);
dea:ema(diff,m);
macd:2*(diff-dea);
ma5:ma(c,5);
ma10:ma(c,10);
VARIABLE:mark:=0;
conpkkd:macd>0 and cross(diff,0); //平空开多
conpdkk:macd<0 and cross(0,diff); //平多开空
dtzs:=holding>0 and (avgenterprice-c)/avgenterprice>0.05; //多头止损条件
ktzs:=holding<0 and (c-avgenterprice)/avgenterprice>0.05; //空头止损条件
dtzy:=holding>0 and cross(ma10,ma5); //多头止盈条件
ktzy:=holding<0 and cross(ma5,ma10); //空头止盈条件
if dtzs or ktzs then begin
多头止损:sell(holding>0,holding,market);
空头止损:sellshort(holding<0,holding,market);
end
if dtzy or ktzy then begin
多头止盈:sell(holding>0,holding,market);
空头止盈:sellshort(holding<0,holding,market);
mark:=1;
end
if conpkkd then begin
sellshort(holding<0,holding,market);
buy(holding=0,1,market);
mark:=0;
end
if conpdkk then begin
sell(holding>0,holding,market);
buyshort(holding=0,1,market);
mark:=0;
end
if type(1)=2 and mark and cross(ma5,ma10) and diff>0 and macd>0 then 止盈后开多:buy(holding=0,1,market);
if type(1)=4 and mark and cross(ma10,ma5) and diff<0 and macd<0 then 止盈后开空:buyshort(holding=0,1,market);
if type(1)=1 and mark and cross(ma10,ma5) and diff>0 and macd>0 then 止盈后平多:sell(1,holding,market);
if type(1)=3 and mark and cross(ma5,ma10) and diff<0 and macd<0 then 止盈后平空:sellshort(1,holding,market);