GLOBALVARIABLE:n1=0,n2=0,n3=0;
GLOBALVARIABLE:tt1=0,tt2=0,tt3=0;
oo:=VALUEWHEN(todaybar=1,o);
if l<open-20*mindiff and n1=0 and
time<>tt1 then begin
tbuy(1,11,mkt);
n1:=1;
tt1:=time;
end
if c<oo-60*mindiff and n2=0 and time<>tt2
then begin
tbuy(1,22,mkt);
n2:=1;
tt2:=TIME;
END
if c<oo-80*mindiff and n3=0 and time<>tt3
then begin
tbuy(1,44,mkt);
n3:=1;
tt3:=time;
end
if time=closetime(0) then begin
n1:=0;
n2:=0;
n3:=0;
tt1:=0;
tt2:=0;
tt3:=0;
end
GLOBALVARIABLE:num=0;
PD:=(DYNAINFO(7)-TAVGENTERPRICEEX2('','',0))*TBUYHOLDING(1)*DYNAINFO(209)>500;
debugfile('D:\test.txt','当前盈亏为%.2f',TOPENPROFIT);
盈亏:=(DYNAINFO(7)-TAVGENTERPRICEEX2('','',0))*TBUYHOLDING(1)*DYNAINFO(209);
debugfile('D:\test2.txt','当前盈亏为%.2f',盈亏);
if PD and
tbuyholding(1)>0 and num=0 THEN begin
tsell(1,TbuyHOLDING(1)/3,mkt);
num:=1;
end
PD2:=(DYNAINFO(7)-TAVGENTERPRICEEX2('','',0))*TBUYHOLDING(1)*DYNAINFO(209)>1000;
if PD2 and
tbuyholding(1)>0 and num=1 THEN begin
tsell(1,TbuyHOLDING(1)/3,mkt);
num:=2;
end
PD3:=(DYNAINFO(7)-TAVGENTERPRICEEX2('','',0))*TBUYHOLDING(1)*DYNAINFO(209)>2000;
if PD3 and
tbuyholding(1)>0 THEN begin
tsell(1,TbuyHOLDING(1),mkt);
end
4.逆势加仓(空)
GLOBALVARIABLE:n1=0,n2=0,n3=0;
GLOBALVARIABLE:tt1=0,tt2=0,tt3=0;
oo:=VALUEWHEN(todaybar=1,o);
if c>oo+20*DYNAINFO(208)and n1=0 and time>tt1+15
then begin
TBUYSHORT(1,11,mkt);
n1:=1;
tt1>TIME;
END
if c>oo+40*DYNAINFO(208) and n2=0 and
time>tt2+15 then begin
TBUYSHORT(1,22,mkt);
n2:=1;
tt2>TIME;
END
if c>oo+80*DYNAINFO(208) and n3=0 and
time>tt3+15 then begin
TBUYSHORT(1,44,mkt);
n3:=1;
tt3>time;
end
GLOBALVARIABLE:num=0;
PK:=(TAVGENTERPRICEEX2('','',1)-DYNAINFO(7))*TSELLHOLDING(1)*DYNAINFO(209)>500;
debugfile('D:\test.txt','当前盈亏为%.2f',TOPENPROFIT);
盈亏:=(DYNAINFO(7)-TAVGENTERPRICEEX2('','',0))*TBUYHOLDING(1)*DYNAINFO(209);
debugfile('D:\test2.txt','当前盈亏为%.2f',盈亏);
if PK and
TSELLHOLDING(1)>0 and num=0 THEN begin
tsellshort(1,TSELLHOLDING(1)/3,mkt);
num:=1;
end
PK2:=(TAVGENTERPRICEEX2('','',1)-DYNAINFO(7))*TSELLHOLDING(1)*DYNAINFO(209)>1000;
if PK2 and
TSELLHOLDING(1)>0 and num=1 THEN begin
tsellshort(1,TSELLHOLDING(1)/3,mkt);
num:=2;
end
PK3:=(TAVGENTERPRICEEX2('','',1)-DYNAINFO(7))*TSELLHOLDING(1)*DYNAINFO(209)>2000;
if PK3 and
TSELLHOLDING(1)>0 THEN begin
tsellshort(1,TSELLHOLDING(1),mkt);
end
if c>oo+20*DYNAINFO(208)and n1=0 and time>tt1+15 then begin
TBUYSHORT(1,11,mkt);
n1:=1;
tt1>TIME;
END
if c>oo+40*DYNAINFO(208) and n2=0 and time>tt2+15 then begin
TBUYSHORT(1,22,mkt);
n2:=1;
tt2>TIME;
END
if c>oo+80*DYNAINFO(208) and n3=0 and time>tt3+15 then begin
TBUYSHORT(1,44,mkt);
n3:=1;
tt3>time;
end
可以,但是修改之后此类全局变量是所有公式都能用的,而不是仅限于当前的策略;
赋值方法:
if c>o then extgbdataset('tt1',time);//当c>O时把time赋值给tt1
取值方法:
ss:=extgbdata('tt1');//获取tt1的值,并赋值给ss
举个例子:
if l<open-20*mindiff and n1=0 and time<>tt1 then begin
tbuy(1,11,mkt);
n1:=1;
tt1:=time;
end
改成
if l<open-20*mindiff and extgbdata('n1')=0 and time<>extgbdata('tt1') then begin
tbuy(1,11,mkt);
extgbdataset('n1',1);
extgbdataset('tt1',time);
end