[PEL] 复制代码
variable:maxprofit1:=-1,maxprofit2:=-1;
//浮动盈亏百分比(基于持仓均价的盈亏幅度)
fdyk1:100*(c-avgenterprice)/avgenterprice;//多头
fdyk2:100*(avgenterprice-c)/avgenterprice;//空头
//无持仓了,直接重置记录的最大浮盈百分比的记录
if avgenterprice=0 then
begin
maxprofit1:=-1;
maxprofit2:=-1;
end
//第一次有持仓时候 给最大盈亏百分比变量 赋值
if HOLDING>0 and maxprofit1=-1 then maxprofit1:=fdyk1;
if HOLDING<0 and maxprofit2=-1 then maxprofit2:=fdyk2;
//更新浮动盈亏百分比最大值
if fdyk1>maxprofit1 and maxprofit1<>-1 then maxprofit1:=fdyk1;
if fdyk2>maxprofit2 and maxprofit2<>-1 then maxprofit2:=fdyk2;
//盈利幅度回撤
if between(avgenterprice,0,1) and fdyk1<0.25*maxprofit1 then sell(1,0,market);
if between(avgenterprice,1,2) and fdyk1<0.33*maxprofit1 then sell(1,0,market);
if avgenterprice>2 and fdyk1<0.75*maxprofit1 then sell(1,0,market);
if between(avgenterprice,0,1) and fdyk2<0.25*maxprofit2 then sellshort(1,0,market);
if between(avgenterprice,1,2) and fdyk2<0.33*maxprofit2 then sellshort(1,0,market);
if avgenterprice>2 and fdyk2<0.75*maxprofit2 then sellshort(1,0,market); |