以文本方式查看主题

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

--  作者:qq代人发帖
--  发布时间:2014/6/17 9:34:56
--  代码问题
请教:下面这段代码前面那两句平仓代码是什么意思,为什么一旦出现平仓后,后面即使条件成立当天也不会再有开仓了呢?

variable:a1=1;
tn:=1;//交易手数
cx:=1;//最大持仓量
xd:=3;//提前下单量(秒)
//交易时间区间
p1:=time>091500 and time<150000;
p2:=if(islastbar,dynainfo(207),time);
p3:=time0-timetot0(p2),linethick0;

r1:=barslast(date<>ref(date,1));
r2:=ref(o,r1);

hd:=if(islastbar,8,2.0);
hd1:=if(islastbar,3,0.2);

r10:=ref(asset,r1+1);
if r10-asset>3000 then a1:=-1;
if asset-r10>2000 then a1:=-1;
MA1:=MA(CLOSE,5);
MA2:=MA(CLOSE,25);

if a1<0 and p3<=xd then
begin
sell(1,tn,limitr,c-hd1);
sellshort(1,tn,limitr,c+hd1);
end

//*******************************
if cross(ma1,ma2) and a1>0 and p1 and p3<=xd then
begin
sellshort(holding<0,tn,limitr,c+hd1);
buy(holding=0,tn,limitr,c+hd1);
end

if cross(ma2,ma1) and a1>0 and p1 and p3<=xd then
begin
sell(holding>0,tn,limitr,c-hd1);
buyshort(holding=0,tn,limitr,c-hd1);
end
    
//**********收盘前清仓***********
if p2>=151000 then
begin
sellshort(holding<0,abs(holding),limitr,c+hd1);
sell(holding>0,holding,limitr,c-hd1);
a1:=1;
end


--  作者:jinzhe
--  发布时间:2014/6/17 9:43:21
--  
不是最后两句导致不再开仓,而是P1的时间限定住了开仓时间
--  作者:zsg465341578
--  发布时间:2014/6/17 9:50:08
--  
老师,那个P1的意思我知道,我是看不明白下面这几句代码的意思,为什么有时早盘出现平仓后,全天也不会开单了呢?
if a1<0 and p3<=xd then
begin
sell(1,tn,limitr,c-hd1);
sellshort(1,tn,limitr,c+hd1);
end
--  作者:jinzhe
--  发布时间:2014/6/17 9:56:09
--  
那是因为有A1作为判断,当日亏损超过3000或者盈利超过2000之后,A1这个标志就置为-1,而开仓需要A1>0
--  作者:zsg465341578
--  发布时间:2014/6/17 10:01:37
--  
意思明白了,这个代码对实盘交易有效吗?
--  作者:jinzhe
--  发布时间:2014/6/17 10:33:33
--  
代码编译之后没问题就可以运行, 实盘效果怎么样我们不能保证