variable:lossnum=0;// 全局变量,平仓时判断一下是盈利/亏损,若亏损lossnum就加1
cs:=2000;//限定亏损次数
if month<>ref(month,1) then lossnum:=0;// 月初时候重置0
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);