[PEL] 复制代码
input:m1(4,1,100,10),m2(8,1,100,10),m3(16,1,100,10),m4(32,1,100,10);
bbi:(ma(close,m1)+ma(close,m2)+ma(close,m3)+ma(close,m4))/4;
input:ss(5,1,100,1);//开仓手数;
cz:abs(bbi-ref(bbi,1));
up:bbi>ref(bbi,1);
down:bbi<ref(bbi,1);
平空开多:up and ref(up,1) and c>bbi and cz>ref(cz,1);
平多开空:down and ref(down,1) and c<bbi and cz>ref(cz,1) ;
variable:maxprofit=0,P1:=0,P2:=0;//有仓位时最大获利幅度 //普通开仓
if 平空开多 then begin
sellshort(holding<0,0,marketr);
buy(holding=0,ss,marketr); maxprofit:=0;
end
if 平多开空 then
begin
sell(holding>0,0,marketr);
buyshort(holding=0,ss,marketr);
maxprofit:=0;
end
IF P1<>0 AND h>=P1 AND HOLDING=0 AND NUMPROFIT(1)>0 THEN begin 止盈后开多:BUY(1,SS,MARKET); end
IF P2<>0 AND L<=P2 AND HOLDING=0 AND NUMPROFIT(1)>0 THEN 止盈后开空:BUYSHORT(1,SS,MARKET);
//判断当前持仓状态下的最大盈利
win:=0; win2:=0;
if holding > 0 and enterbars > 0 then
begin
P2:=0;
win:=(h-enterprice); //记录最大盈利点数
if win>maxprofit then BEGIN maxprofit:=win; P1:=H;END
win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end
if holding < 0 and enterbars > 0 then
begin
P1:=0;
win:=(enterprice-l); //记录最大盈利点数
if win > maxprofit then BEGIN maxprofit:=win;P2:=L; END
win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end
浮动盈亏点数:win;
最大盈利:maxprofit;
浮动盈亏幅度:100*win/AVGENTERPRICE;
//出现浮动亏损比如2%平仓
多止损:sell(浮动盈亏幅度 < -2,0,marketr);
if win2 >= 60 and openprofit > 0 then
begin
多止赢:sell(1, 0,marketr);
end
//出现浮动亏损比如2%平仓
空止损:sellshort(浮动盈亏幅度 < -2,0,marketr);
IF win2 >= 60 and openprofit > 0 THEN
BEGIN
空止赢:sellshort(1, 0,marketr);
END