[PEL] 复制代码 MA1:=MA(CLOSE,5);
MA2:=MA(CLOSE,30);
variable:maxprofit1=0,maxprofit2=0;//有仓位时最大获利幅度
//开仓
IF CROSS(MA1,MA2) and holding=0 THEN
BEGIN
BUY(1,1,limit,c);
maxprofit1:=0;
END
//平仓
SELL(CROSS(MA2,MA1),0,limit,c);
//判断当前持仓状态下的最大盈利
dwin:=0;
dwin2:=0;
if holding > 0 and enterbars > 0 then
begin
dwin:=(c-enterprice)/enterprice*100;
if dwin>maxprofit1 then //记录最大盈利
maxprofit1:=dwin;
dwin2:=(maxprofit1-dwin)/maxprofit1*100; //最大盈利后的回调幅度
end
//出现浮动亏损比如2%平仓
多止损:SELL(dwin < -2,0,limit,c);
//出现最高盈利后,回落到盈利的60%平仓出场
多止赢:SELL(dwin2 >= 60 and openprofit > 0, 0,limit,c);
///////////////////////////////////////////////////
//空部分
IF CROSS(MA2,MA1) and holding=0 THEN
BEGIN
BUYSHORT(1,1,limit,c);
maxprofit2:=0;
END
SELLSHORT(CROSS(MA1,MA2),0,limit,c);
kwin:=0;
kwin2:=0;
if holding < 0 and enterbars > 0 then
begin
kwin:=(enterprice-c)/enterprice*100;
if kwin > maxprofit2 then
maxprofit2:=kwin;
kwin2:=(maxprofit2-kwin)/maxprofit2*100;
end
空止损:SELLSHORT(kwin < -2,0,limit,c);
空止赢:SELLSHORT(kwin2 >= 60 and openprofit > 0, 0,limit,c); |