VARIABLE:n=1,盈亏=0;
macd:stkindi('','macd.macd1',0,1);
diff:stkindi('','macd.diff',0,1);
jc:cross(diff,macd);//金叉
sc:cross(macd,diff);//死叉
if date<>ref(date,1) then begin //第二天重置为0重新计算
n:=1;
盈亏:=0;
end
if n>=5 then n:=5;
if jc and n<=5 THEN begin
sellshort(holding<0,holding,market);
buy(holding=0,n,market);
盈亏:=NUMPROFIT(1)+盈亏;
if 盈亏<0 and n<5 then n:=n+1;
if 盈亏>0 then n:=1;
end
if sc and n<=5 then BEGIN
sell(holding>0,holding,market);
buyshort(holding=0,n,market);
盈亏:=NUMPROFIT(1)+盈亏;
if 盈亏<0 and n<5 then n:=n+1;
if 盈亏>0 then n:=1;
end
if hhv(h,enterbars+1)-l>=40*mindiff then
sell(holding>0,holding,market);
if h-llv(l,enterbars+1)>=40*mindiff then
sellshort(holding<0,holding,market);