交易条件加上
asset-ref(asset,todaybar)<=0
variable:n=0;//n计算亏损总点数
if 平多条件1 and 持仓判断 then begin
sell(1,0,下单价位);
if numprofit(1)<0 then n:=n+(exitprice-enterprice)*手数1;//手数1是开仓手数
end
if 平空条件1 and 持仓判断 then begin
sellshort(1,0,下单价位);
if numprofit(1)<0 then n:=n+(enterprice-exitprice)*手数2;//手数2也是开仓手数
end
//这只是简单的例举了开多开空两种情况,如果公式里面有多个开多开空语句,那么就要按照上面的方法多写几遍
s1:=n*MULTIPLIER;//亏损总金额
if openprofit>0 then
ss:=abs(s1)/abs(enterprice-c)/MULTIPLIER;//在盈利的情况下,把亏损总金额除以当前的开平价差,再除以合约单位,得出需要多少手,可能会有小数点
tt:=floor(ss);//把求出的手数向下取整,则得出平掉亏损持仓需要平掉当前多少手