以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  改写一下,实现立即下单  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=48887)

--  作者:eric917
--  发布时间:2013/2/25 16:28:18
--  改写一下,实现立即下单

ss:=1; //手数
maa:ema(c,10);
tt1:=H>maa;
tt2:=L<maa;
//当开始没有持仓
if holding=0 then begin
if tt1 then begin
buy(1,ss,market)
end

if tt2 then begin
buyshort(1,ss,market);
end
end

//持仓状态

if tt1 and holding<0 and enterbars>=0 then begin
sellshort(1,ss,market);
buy(1,ss,market);
end

if tt2 and holding>0 and enterbars>=0 then begin
sell(1,ss,market);
buyshort(1,ss,market);
end

 

aa-TT:if(TT1,1,if(TT2,-1,0)),NODRAW;
bb-holding:holding,NODRAW;
cc-Enterbars:enterbars,nodraw;

 

上面的代码,我想实现下面要求

一根K线只出现一次同方向的平开(上面的代码实盘运行过,是会两边一起开仓的),这个和金字塔限制说明的有所不同

 

请问怎么实现

 



--  作者:jinzhe
--  发布时间:2013/2/25 16:31:14
--  

全局变量限制下单


--  作者:eric917
--  发布时间:2013/2/25 22:20:41
--  

请问这样可以不?

ss:=1; //手数
extgbdataset(\'t1_position\',0);
//0表示没有仓位,1表示持有多头, -1表示持有空头
extgbdataset(\'t1_holding\',0);
//0表示没有仓位,>0表示持有多头, <0表示持有空头
extgbdataset(\'t1_enterbarpos\',0);//记录其开仓的K线

maa:ema(c,10);
bpk:=cross(c,maa);
spk:=cross(maa ,c);

if not(islastbar) or workmode<>1 then exit;

//如果当前棒是最后一根k线,执行
if islastbar and  time<151000 then begin

 // 如果最后一根k线发生过出场信号,则那一根k线不再交易
 if extgbdata(\'t1_enterbarpos\') = barpos then begin
  goto continueline ;
 end
 
//没有持仓状态
if extgbdata(\'t1_position\')=0  and extgbdata(\'t1_holding\')=0 then begin
     if  bpk then begin
  
        tbuy(1,ss,mkt);
        extgbdataset(\'t1_position\',1);
        extgbdataset(\'t1_holding\',ss);
        extgbdataset(\'t1_enterbarpos\',barpos);
     
      end

      if spk then begin
      
         tbuyshort(1,ss,mkt);
         extgbdataset(\'t1_position\',-1);
         extgbdataset(\'t1_holding\',-ss);
         extgbdataset(\'t1_enterbarpos\',barpos);
        
      end
    goto continueline ;
end//没有持仓状态
    
//持有仓位状态
   //持空头
if bpk and extgbdata(\'t1_position\')=-1   and  extgbdata(\'t1_holding\')<0 then begin

       tsellshort(1,ss,mkt);
       tbuy(1,ss,mkt);
       extgbdataset(\'t1_position\',1);
       extgbdataset(\'t1_holding\',ss);
       extgbdataset(\'t1_enterbarpos\',barpos);
       goto continueline ;
end
    //持多头
if spk and extgbdata(\'t1_position\')=1    and  extgbdata(\'t1_holding\')>0  then begin

        tsell(1,ss,mkt);
        tbuyshort(1,ss,mkt);
        extgbdataset(\'t1_position\',-1);
        extgbdataset(\'t1_holding\',-ss);
        extgbdataset(\'t1_enterbarpos\',barpos);
        goto continueline ;
end

end//if  如果是最后K线 ISLASTBAR

 

if  time>=151300 then begin

             tsell(extgbdata(\'t1_holding\')>0,ss,mkt);
             tsellshort(extgbdata(\'t1_holding\')>0,ss,mkt);
             extgbdataset(\'t1_position\',0);
             extgbdataset(\'t1_holding\',0);
                     
end


continueline@ 资产:tasset,linethick0;
position:=extgbdata(\'t1_position\');
t1holding:=extgbdata(\'t1_holding\');
debugfile(\'d:\\debug\\803555.txt\',\'position=%.0f\' ,position) ;
debugfile(\'d:\\debug\\803555.txt\',\'t1holding=%.0f\' ,t1holding) ;

 

 

[此贴子已经被作者于2013-2-25 22:21:59编辑过]

--  作者:eric917
--  发布时间:2013/2/25 22:50:18
--  

上面有些不合理的地方,修改了一下:

 

ss:=1; //手数
extgbdataset(\'t1_position\',0);
//0表示没有仓位,1表示持有多头, -1表示持有空头
extgbdataset(\'t1_holding\',0);
//0表示没有仓位,>0表示持有多头, <0表示持有空头
extgbdataset(\'t1_enterbarpos\',0);//记录其开仓的K线

maa:ema(c,10);
bpk:=cross(c,maa);
spk:=cross(maa ,c);
//非最后一根K线退出
if not(islastbar) or workmode<>1 then exit;

//如果当是最后一根k线,执行
IF islastbar and  time<151000 then begin

 // 如果最后一根k线发生过开仓信号,则那一根k线不再交易
 if extgbdata(\'t1_enterbarpos\') = barpos then begin
  goto continueline ;
 end
 
//没有持仓状态
if extgbdata(\'t1_position\')=0  and extgbdata(\'t1_holding\')=0 then begin
     if  bpk then begin
       
        tbuy(1,ss,mkt);
        extgbdataset(\'t1_position\',1);
        extgbdataset(\'t1_holding\',ss);
        extgbdataset(\'t1_enterbarpos\',barpos);
        goto continueline ;
       
      end

      if spk then begin
      
         tbuyshort(1,ss,mkt);
         extgbdataset(\'t1_position\',-1);
         extgbdataset(\'t1_holding\',-ss);
         extgbdataset(\'t1_enterbarpos\',barpos);
         goto continueline ;
        
      end
end//没有持仓状态
    
//持有仓位状态
   //持有空头
if bpk and extgbdata(\'t1_position\')=-1   and  extgbdata(\'t1_holding\')<0 then begin

       tsellshort(1,ss,mkt);
       tbuy(1,ss,mkt);
       extgbdataset(\'t1_position\',1);
       extgbdataset(\'t1_holding\',ss);
       extgbdataset(\'t1_enterbarpos\',barpos);
       goto continueline ;
      
end
    //持有多头
if spk and extgbdata(\'t1_position\')=1    and  extgbdata(\'t1_holding\')>0  then begin

        tsell(1,ss,mkt);
        tbuyshort(1,ss,mkt);
        extgbdataset(\'t1_position\',-1);
        extgbdataset(\'t1_holding\',-ss);
        extgbdataset(\'t1_enterbarpos\',barpos);
        goto continueline ;
       
end
END//if  ISLASTBAR

if  time>=151300 then begin

             tsell(extgbdata(\'t1_holding\')>0,ss,mkt);
             tsellshort(extgbdata(\'t1_holding\')<0,ss,mkt);
             extgbdataset(\'t1_position\',0);
             extgbdataset(\'t1_holding\',0);
                     
end

continueline@ 资产:tasset,linethick0;
position:=extgbdata(\'t1_position\');
t1holding:=extgbdata(\'t1_holding\');
debugfile(\'d:\\debug\\803555.txt\',\'position=%.0f\' ,position) ;
debugfile(\'d:\\debug\\803555.txt\',\'t1holding=%.0f\' ,t1holding) ;

 

 


--  作者:admin
--  发布时间:2013/2/25 23:31:48
--  

后台的代码直接贴给我们的客服我们是很难从中看到逻辑问题的,因为你的交易思路我们无法准确的了解。

建议你多看看 http://www.weistock.com/bbs/dispbbs.asp?boardid=4&Id=332 问题4中的后台调试部分,加入代码的变量跟踪部分,也就是DEBUGFILE函数输出你代码中的变量值,然后多进行跟踪调试,这样才能发现其中的不合理部分


--  作者:eric917
--  发布时间:2013/2/26 9:35:06
--  

好的,我试试,谢谢