[PEL] 复制代码 GLOBALVARIABLE:maxprofit1:=-1,maxprofit2:=-1;
多持仓均价:tAVGENTERPRICEex2('',STKLABEL,0);
空持仓均价:tAVGENTERPRICEex2('',STKLABEL,1);
//浮动盈亏百分比(基于持仓均价的盈亏幅度)
fdyk1:100*(c-多持仓均价)/多持仓均价;//多头
fdyk2:100*(空持仓均价-c)/空持仓均价;//空头
//无持仓了,直接重置记录的最大浮盈百分比的记录
if 多持仓均价=0 then maxprofit1:=-1;
if 空持仓均价=0 then maxprofit2:=-1;
//第一次有持仓时候 给最大盈亏百分比变量 赋值
if 多持仓均价<>0 and maxprofit1=-1 then maxprofit1:=fdyk1;
if 空持仓均价<>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(多持仓均价,0,1) and fdyk1<0.25*maxprofit1 then tsell(1,0,mkt);
if BETWEEN(多持仓均价,1,2) and fdyk1<0.33*maxprofit1 then tsell(1,0,mkt);
if 多持仓均价>2 and fdyk1<0.75*maxprofit1 then tsell(1,0,mkt);
if BETWEEN(空持仓均价,0,1) and fdyk2<0.25*maxprofit2 then tsellshort(1,0,mkt);
if BETWEEN(空持仓均价,1,2) and fdyk2<0.33*maxprofit2 then tsellshort(1,0,mkt);
if 空持仓均价>2 and fdyk2<0.75*maxprofit2 then tsellshort(1,0,mkt);
以上范例供参考~ |