variable:ykcs=0;//申明全局变量ykcs
yingkui:=exitprice-enterprice;//计算上次开平仓差值
cound1:=(holding=-1 and ...) ;//当持有空单时且。。。
cound2:=(holding=1 and ...);//当持有多单是且。。。
if cound1 then begin
if holding=-1 then sellshort(1,1,market);//平仓
ifelse(yingkui>=0,ykcs:=ykcs+1,ykcs:=0);//上次交易是否盈利,若盈利则ykcs变为0.否则+1
if holding=0 and ykcs<3 then buy(1,1,market);//若ykcs<3,则反向开仓。若ykcs=3则不再开仓
end
if cound2 then begin//
if holding=1 then sell(1,1,market);//
ifelse(yingkui>=0,ykcs:=0,ykcs:=ykcs+1);//
if holding=0 and ykcs<3 then buyshort(1,1,market);//
end
ifelse(ykcs=3,0,ykcs);//当ykcs=3时,则等待cound3,cound4出现再开仓
cound3:=(holding=0 and ...);//
cound4:=(holding=0 and ...);//
if cound3 then buy(1,1,market);//在没有单的情况下重新开多单
if cound4 then buyshort(1,1,market);//在没有单的情况下重新开空单
1.有问题的是红线的句子会不会存在这个单还没成交,而下面的yingkui计算的是上上次平仓价格和这次的开仓价格差值。
2.ykcs=3回到0后没等到cound3,cound4,就按照 if holding=0 and ykcs<3 then buy(1,1,market);//若ykcs<3,则反向开仓。若ykcs=3则不再开仓。重新开仓了。
3.cound1,cound2中的条件是holding<>0,会不会和下面的if内的holding=0(反向开仓)冲突。