variable:n=0;
if 开仓条件 and NUMPROFIT(1)>0 and n<3 then n:=n+1;
if 开仓条件 and NUMPROFIT(1)>0 and n=3 then buy();