欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → 后台模板套入后的问题

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有7045人关注过本帖树形打印复制链接

主题:后台模板套入后的问题

帅哥哟,离线,有人找我吗?
eric917
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:271 积分:730 威望:0 精华:0 注册:2011/6/22 15:58:05
后台模板套入后的问题  发帖心情 Post By:2013/2/26 11:28:39    Post IP:58.246.57.26[显示全部帖子]

环境介绍:

//运行周期:1分钟

//运行模式:固定时间间隔,1秒轮询 

//运行品种:IF1303

 

会多个策略对改品种下单,希望各策略的开平仓独立,每个策略管好自己的开平仓 

系统很简单,就是最高价突破均线平空开多,最低价突破平多开空,每根K线都只开平一次,开仓后当根K线后面的信号可以忽略

 

 

利用火哥的模板http://www.weistock.com/bbs/dispbbs.asp?boardid=10&id=9112

蓝色为测试的图表交易系统:

globalvariable:hold=drawnull;

//以下为系统内容
ss:=1; //手数
//variable:myenterbars=0;

maa:ema(c,10);
tt1:=h>maa;
tt2:=l<maa;
//当开始没有持仓
if  holding=0 then begin
     if tt1 then  begin
         buy(1,ss,market)
         goto continueline;
     end
    
     if tt2 then begin
        buyshort(1,ss,market);
        goto continueline;
     end
end

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

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

continueline@ 资产:tasset,linethick0;
aa-tt:if(tt1,1,if(tt2,-1,0)),nodraw;
bb-holding:holding,nodraw;
cc-enterbars:enterbars,nodraw;

//以上为模型内容

 

cc803555:=holding;//这句放在信号稳定的地方

drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc803555,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;


xiadan803555:=cc803555-hold;
if xiadan803555>0.5 then begin
cang:=min(xiadan803555,abs(hold));


if hold<0 then begin
tsellshort(1,cang,mkt,0,0,'803555'),allowrepeat;
debugfile('d:\803555.txt',numtostr(hold,0)+' '+numtostr(cc803555,0)+' 平空 %.0f',cang);
end
cang:=xiadan803555+min(hold,0);


if cang>0 then begin
tbuy(1,cang,mkt,0,0,'803555'),allowrepeat;
debugfile('d:\803555.txt',numtostr(hold,0)+' '+numtostr(cc803555,0)+' 开多 %.0f',cang);
end
end
if xiadan803555<-0.5 then begin
cang:=min(abs(xiadan803555),abs(hold));
if hold>0 then begin
tsell(1,cang,mkt,0,0,'803555'),allowrepeat;
debugfile('d:\803555.txt',numtostr(hold,0)+' '+numtostr(cc803555,0)+' 平多 %.0f',cang);
end


cang:=abs(xiadan803555)-max(hold,0);
if cang>0 then begin
tbuyshort(1,cang,mkt,0,0,'803555'),allowrepeat;
debugfile('d:\803555.txt',numtostr(hold,0)+' '+numtostr(cc803555,0)+' 开空 %.0f',cang);
end
end
hold:=cc803555;

 

运行环境:(1手单)1分钟 IF1303 逐K模式  账号为虚拟账号

图表系统单独运行,测试正常

套入后台模板后,有几个问题:

1)单账号没有持仓的时候,交易正常

2)当我手动将账号调成2手多头2手空头同时持有,再加载这个后台系统,系统开始只会把其中的一手空仓或者多仓做反手(就是系统一直都是持有4手单),总单量没变

3)之前在图表加载的时候,一根K线只会执行一次开平仓,但套入后套模板后,却会在同一K线出现多次开平仓(不知道是不是因为模板里面的allowrepeat函数问题),

     请问是否将其去除就不会出现多次开平仓的问题?

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
eric917
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:271 积分:730 威望:0 精华:0 注册:2011/6/22 15:58:05
  发帖心情 Post By:2013/2/26 16:05:47    Post IP:219.136.141.231[显示全部帖子]

同样的交易系统,我也写了一个后台程序:

 

 

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:=h>maa;
spk:=l<maa;
//非最后一根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) ;

 

如果上模板不能很好执行,不知道我这个能否可行,谢谢

 

 

[此贴子已经被作者于2013-2-26 16:06:06编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
eric917
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:271 积分:730 威望:0 精华:0 注册:2011/6/22 15:58:05
  发帖心情 Post By:2013/2/28 11:17:41    Post IP:219.136.138.12[显示全部帖子]

谢谢老师

 回到顶部
帅哥哟,离线,有人找我吗?
eric917
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:271 积分:730 威望:0 精华:0 注册:2011/6/22 15:58:05
  发帖心情 Post By:2013/2/28 13:23:06    Post IP:219.136.138.12[显示全部帖子]

老师,还有个小问题想请教

你的模型在没有持仓的环境下已经测试过,可以正常运行

 

然后在换一下环境,在账号里面先各开一张多单和空单,然后把全局变量清零


图片点击可在新窗口打开查看此主题相关图片如下:111.jpg
图片点击可在新窗口打开查看

之后开始运行,发现监控其启动操作,第一个操作时平仓


图片点击可在新窗口打开查看此主题相关图片如下:222.jpg
图片点击可在新窗口打开查看

这样如果账号有持仓就会少了1手单,请问这样应该怎么加条件限制,第一次只开仓而不平仓呢?

麻烦老师,谢谢!!!


 回到顶部