variable:bj=0;
variable:ss=0;
定义全局变量,ss用来记录是否体总体的盈利亏损值,bj用来对亏损超过70之后做标记
if 开多条件 and bj=0 and holding=0 then buy......;
if 开空条件 and bj=0 and holding=0 then buyshort......;
所有的开多开空条件都需要这样写,多加一个bj=0的条件
if 平多条件 and holding>0 then begin
sell(1,平仓手数,thisclose);
ss:=ss+exitprice-enterprice;
end
if 平空条件 and holding<0 then begin
sellshort(1,平仓手数,thisclose);
ss:=ss+enterprce-exitprice;
end
所有的平多和平空语句都要这样写:1 条件里面多加一个holding判断 2要多加一句ss赋值
if ss<=-70 then bj:=1;
当总体亏损过70之后,bj赋值为1,那么开仓条件里面的bj=0 的条件就不满足,从而达到无法开仓的效果
if time=closetime(0) then bj:=0;
收盘之后重新把bj重新赋值为0,不影响第二天的亏损计算
variable:n=0;
variable:bj=0;
MA1:=ema(o,5);
MA2:=ema(o,10);
开仓手数:=1;
平空开多条件:=MA1>MA2 and (HOLDING<=0);
平多开空条件:=MA1<MA2 and (HOLDING>=0);
T1:=((TIME>91500) and (TIME<151500));
T2:=(TIME>=151500);
开盘开多条件:=MA1>MA2 ;
开盘开空条件:=MA1<MA2 ;
收盘平多:SELL((T2 and (HOLDING>0)),HOLDING,THISCLOSE);
收盘平空:SELLSHORT((T2 and (HOLDING<0)),HOLDING,THISCLOSE);
if (开盘开多条件) and holding=0 and bj=0 then BUY(((HOLDING=0) and T1),开仓手数,THISCLOSE);
if (开盘开空条件) and holding=0 and bj=0 then BUYSHORT(((HOLDING=0) and T1),开仓手数,THISCLOSE);
if (平空开多条件) and holding<0 then
begin
SELLSHORT((HOLDING<0),HOLDING,THISCLOSE);
n:=enterprice-exitprice+n;
if n<=-70 then bj:=1;
end
if (平多开空条件) then
begin
SELL((HOLDING>0),HOLDING,THISCLOSE);
n:=n+exitprice-enterprice;
if n<=-70 then bj:=1;
end
if time=closetime(0) then begin
bj:=0;
n:=0;
end
variable:n=0;
variable:bj=0;
MA1:=ema(o,5);
MA2:=ema(o,10);
开仓手数:=1;
平空开多条件:=MA1>MA2 and (HOLDING<=0);
平多开空条件:=MA1<MA2 and (HOLDING>=0);
T1:=((TIME>91500) and (TIME<151500));
T2:=(TIME>=151500);
开盘开多条件:=MA1>MA2 ;
开盘开空条件:=MA1<MA2 ;
收盘平多:SELL((T2 and (HOLDING>0)),HOLDING,THISCLOSE);
收盘平空:SELLSHORT((T2 and (HOLDING<0)),HOLDING,THISCLOSE);
if (平空开多条件) and holding<0 then
begin
SELLSHORT((HOLDING<0),HOLDING,THISCLOSE);
n:=enterprice-exitprice+n;
if n<=-70 then bj:=1;
end
if (平多开空条件) then
begin
SELL((HOLDING>0),HOLDING,THISCLOSE);
n:=n+exitprice-enterprice;
if n<=-70 then bj:=1;
end
if (开盘开多条件) and holding=0 and bj=0 then BUY(((HOLDING=0) and T1),开仓手数,THISCLOSE);
if (开盘开空条件) and holding=0 and bj=0 then BUYSHORT(((HOLDING=0) and T1),开仓手数,THISCLOSE);
if time=closetime(0) then begin
bj:=0;
n:=0;
end