使用全局变量记录,参考下面的范例:当日亏损5次不在开仓。
variable:lossnum=0;// 全局变量,平仓时判断一下是盈利/亏损,若亏损lossnum就加1
cs:=5;//限定一天最多亏损5次
ma5:=ma(5,close);
ma20:=ma(20,close);
con1:=cross(ma5,ma20);
con2:=cross(ma20,ma5);
if cond2 and holding>0 then
begin
sell(1,1,thisclose);
if c<enterprice then lossnum:=lossnum+1;
end
if cond1 and holding=0 and lossnum<cs then buy(1,1,thisclose);
if time=closetime(0) then lossnum:=0;// 商品期货,收盘的同时,lossnum赋值为0
//收盘lossnum不赋值为0,第二天就不再开仓了