以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  关于开仓  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=87509)

--  作者:么么
--  发布时间:2015/11/19 14:18:30
--  关于开仓
老师,我的策略怎么1个周期内开多次仓??
源码:

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

 


--  作者:jinzhe
--  发布时间:2015/11/19 14:35:08
--  

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


里面的 tt1>TIME;这类的语句意义不明,改成tt1:=time;tt2:=time;tt3:=time;
--  作者:么么
--  发布时间:2015/11/19 14:37:23
--  
我把GLOBALVARIABLE改成EXTGBDATA可以吗??


--  作者:jinzhe
--  发布时间:2015/11/19 14:41:33
--  

可以,但是修改之后此类全局变量是所有公式都能用的,而不是仅限于当前的策略;

 

赋值方法:

if c>o then extgbdataset(\'tt1\',time);//当c>O时把time赋值给tt1

 

取值方法:

ss:=extgbdata(\'tt1\');//获取tt1的值,并赋值给ss

[此贴子已经被作者于2015/11/19 14:41:59编辑过]

--  作者:么么
--  发布时间:2015/11/19 14:49:34
--  
不会啊,老师,怎么修改???
--  作者:jinzhe
--  发布时间:2015/11/19 14:58:09
--  

举个例子:

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


--  作者:么么
--  发布时间:2015/11/19 16:48:55
--  
oo:=VALUEWHEN(todaybar=1,o);
ma60:=ma(c,60);
 
if c>oo+2*mindiff and c>ma60  and extgbdata(\'num1\')=0 then begin
tbuy(1,25,mkt);
extgbdataset(\'num1\',1);
END
 

if c>oo+4*mindiff and c>ma60 and extgbdata(\'num2\')=0 and tenterbars>1 then begin
tbuy(1,24,mkt);
extgbdataset(\'num2\',1);
END
 
if c>oo+6*mindiff and c>ma60 and extgbdata(\'num3\')=0 and tenterbars>1 then begin 
tbuy(1,23,mkt);
extgbdataset(\'num3\',1);
end

if c>oo+8*mindiff and c>ma60 and extgbdata(\'num4\')=0 and tenterbars>1 then begin 
tbuy(1,22,mkt);
extgbdataset(\'num4\',1);
end

if c>oo+10*mindiff and c>ma60 and extgbdata(\'num5\')=0 and tenterbars>1 then begin 
tbuy(1,21,mkt);
extgbdataset(\'num5\',1);
end

if c>oo+12*mindiff and c>ma60 and extgbdata(\'num6\')=0 and tenterbars>1 then begin 
tbuy(1,20,mkt);
extgbdataset(\'num6\',1);
end
if c>oo+14*mindiff and c>ma60 and extgbdata(\'num7\')=0 and tenterbars>1 then begin 
tbuy(1,19,mkt);
extgbdataset(\'num7\',1);
end

if c>oo+16*mindiff and c>ma60 and extgbdata(\'num8\')=0 and tenterbars>1 then begin 
tbuy(1,18,mkt);
extgbdataset(\'num8\',1);
end

if c>oo+18*mindiff and c>ma60 and extgbdata(\'num9\')=0 and tenterbars>1 then begin 
extgbdataset(\'num9\',1);
tt9:=time;
end

if c>oo+20*mindiff and c>ma60 and extgbdata(\'num10\')=0 and tenterbars>1 then begin 
tbuy(1,16,mkt);
extgbdataset(\'num10\',1);
end

if c>oo+22*mindiff and c>ma60 and extgbdata(\'num11\')=0 and tenterbars>1 then begin 
tbuy(1,15,mkt);
extgbdataset(\'num11\',1);
end

if c>oo+24*mindiff and c>ma60 and extgbdata(\'num12\')=0 and tenterbars>1 then begin 
tbuy(1,14,mkt);
extgbdataset(\'num12\',1);
end

if c>oo+26*mindiff and c>ma60 and extgbdata(\'num13\')=0 and tenterbars>1 then begin 
tbuy(1,13,mkt);
extgbdataset(\'num13\',1);
end

if c>oo+28*mindiff and c>ma60 and extgbdata(\'num14\')=0 and tenterbars>1 then begin 
tbuy(1,12,mkt);
extgbdataset(\'num14\',1);
end

if c>oo+30*mindiff and c>ma60 and extgbdata(\'num15\')=0 and tenterbars>1 then begin 
tbuy(1,11,mkt);
extgbdataset(\'num15\',1);
end
if c>oo+32*mindiff and c>ma60 and extgbdata(\'num16\')=0 and tenterbars>1 then begin 
tbuy(1,10,mkt);
extgbdataset(\'num16\',1);
end

if c>oo+34*mindiff and c>ma60 and extgbdata(\'num17\')=0 and tenterbars>1 then begin 
tbuy(1,9,mkt);
extgbdataset(\'num17\',1);
end

if c>oo+36*mindiff and c>ma60 and extgbdata(\'num18\')=0 and tenterbars>1 then begin 
tbuy(1,8,mkt);
extgbdataset(\'num18\',1);
end

if c>oo+38*mindiff and c>ma60 and extgbdata(\'num19\')=0 and tenterbars>1 then begin 
tbuy(1,7,mkt);
extgbdataset(\'num19\',1);
end

if c>oo+40*mindiff and c>ma60 and extgbdata(\'num20\')=0 and tenterbars>1 then begin 
tbuy(1,6,mkt);
extgbdataset(\'num20\',1);
end

if c>oo+42*mindiff and c>ma60 and extgbdata(\'num21\')=0 and tenterbars>1 then begin 
tbuy(1,5,mkt);
extgbdataset(\'num21\',1);
end

if c>oo+44*mindiff and c>ma60 and extgbdata(\'num22\')=0 and tenterbars>1 then begin 
tbuy(1,4,mkt);
extgbdataset(\'num22\',1);
end

if c>oo+46*mindiff and c>ma60 and extgbdata(\'num23\')=0 and tenterbars>1 then begin 
tbuy(1,3,mkt);
extgbdataset(\'num23\',1);
end

if c>oo+48*mindiff and c>ma60 and extgbdata(\'num24\')=0 and tenterbars>1 then begin 
tbuy(1,2,mkt);
extgbdataset(\'num24\',1);
end

if c>oo+50*mindiff and c>ma60 and extgbdata(\'num25\')=0 and tenterbars>1 then begin 
tbuy(1,1,mkt);
extgbdataset(\'num25\',1);
end


if DYNAINFO(207)=closetime(0) and tenterbars>0 then begin
    extgbdataset(\'num1\',0);
    extgbdataset(\'num2\',0);
    extgbdataset(\'num3\',0);
    extgbdataset(\'num4\',0);
    extgbdataset(\'num5\',0);
    extgbdataset(\'num6\',0);
    extgbdataset(\'num7\',0);
    extgbdataset(\'num8\',0);
    extgbdataset(\'num9\',0);
    extgbdataset(\'num10\',0);
    extgbdataset(\'num11\',0);
    extgbdataset(\'num12\',0);
    extgbdataset(\'num13\',0);
    extgbdataset(\'num14\',0);
    extgbdataset(\'num15\',0);
    extgbdataset(\'num16\',0);
    extgbdataset(\'num17\',0);
    extgbdataset(\'num18\',0);
    extgbdataset(\'num19\',0);
    extgbdataset(\'num20\',0);
    extgbdataset(\'num21\',0);
    extgbdataset(\'num22\',0);
    extgbdataset(\'num23\',0);
    extgbdataset(\'num24\',0);
    extgbdataset(\'num25\',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,10,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,20,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



--  作者:么么
--  发布时间:2015/11/19 16:49:15
--  
老师,你看一下正确不????
--  作者:jinzhe
--  发布时间:2015/11/19 16:55:43
--  
不对,少了time和tt的判断,
--  作者:么么
--  发布时间:2015/11/19 17:11:37
--  
图片点击可在新窗口打开查看