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


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件策略编写求助区 → 简单的后台模型,麻烦帮忙修改

   

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


  共有11303人关注过本帖平板打印复制链接

主题:简单的后台模型,麻烦帮忙修改

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


加好友 发短信
等级:论坛游民 帖子:271 积分:730 威望:0 精华:0 注册:2011/6/22 15:58:05
  发帖心情 Post By:2013/2/22 11:08:04 [只看该作者]

我按软件带的海龟改了一下

 

加载启动了还是没有动作

 

variable : myentryprice =0 ;   //开仓价格
variable : myexitprice =0 ;   //平仓价格
variable : position=0 ;   //仓位状态

variable : ma20=close ;   //20周期的均线
//0表示没有仓位,1表示持有多头, -1表示持有空头
buyorderthisbar := 0 ;  //当前bar有过交易

variable : _debugout = 1 ;    //是否输出后台交易的调试信息

SS:=1;                       //手数
t20:=20 ;    //进场的周期
//准备需要计算的变量
ma20:=ma(c,20);

BBB:=cross(c,ma20); //bpk
SSS:=cross(ma20,c); //spk

//采用全局变量保存最后一根k线的计算状态
strentrybarpos:=strcat(stklabel,'entrybarpos') ;
strexitbarpos:=strcat(stklabel,'exitbarpos') ;
strpreentryprice:=strcat(stklabel,'preentryprice') ;
strposition:=strcat(stklabel,'position') ;


//没够20根K线,则退出
IF BARPOS<t20 THEN  EXIT;

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

      //恢复上一秒计算时保存的数据
 //如果记录的进场barpos和当前的相等,说明上一个进场信号也是最后一根k线发出的。  
 if extgbdata(strentrybarpos) = barpos then begin
  myentryprice := extgbdata(strpreentryprice) ;
      position := extgbdata(strposition) ;  
 end
     // 如果最后一根k线发生过进场信号,则那一根k线不再交易
 if extgbdata(strentrybarpos) = barpos then begin
  goto continueline;
  
 end
 
//如果当前是没有持仓的状态
 if position=0   then begin
 
     //多头进场条件符合
  if bbb then begin
   myentryprice := ma20+2*mindiff ;   
   position := 1 ;
   
                tbuy(1,ss,mkt);
               
                extgbdataset(strentrybarpos,barpos ) ;
   extgbdataset(strpreentryprice,myentryprice ) ;
   extgbdataset(strposition,position ) ;

      end
     //空头进场条件符合
  if sss  then begin   
   myentryprice := ma20-2*mindiff ;   
   position := -1 ;
 
   tbuyshort( 1,ss,mkt);

   extgbdataset(strentrybarpos,barpos ) ;
   extgbdataset(strpreentryprice,myentryprice ) ;
   extgbdataset(strposition,position ) ; 
  end //if空头进场符合
  
  goto continueline ;
  
 end//if如果当前是没有持仓的状态
 
//如果当前持有空头仓位的状态
      if position = -1   then begin
 //平空仓
  if bbb and extgbdata(strentrybarpos)<>barpos  then begin
   myexitprice := ma20+2*mindiff ;   
   position := 0 ;

   tsellshort( 1,ss,mkt);
   
   extgbdataset(strexitbarpos,barpos ) ;
   extgbdataset(strposition,position ) ;

  end
     //开多仓 
  if bbb and extgbdata(strentrybarpos)<>barpos  then begin
   myentryprice := ma20+2*mindiff ;   
   position := 1 ;
   
                tbuy(1,ss,mkt);
               
                extgbdataset(strentrybarpos,barpos ) ;
   extgbdataset(strpreentryprice,myentryprice ) ;
   extgbdataset(strposition,position ) ;
  end
  
      goto continueline ;
 
      end  //if如果当前持有空头仓位的状态
 
 //如果当前持有多头仓位的状态
      if position = 1   then begin
 //平多仓
  if sss and extgbdata(strentrybarpos)<>barpos  then begin
   myexitprice := ma20-2*mindiff ;   
   position := 0 ;

   tsell(1,ss,mkt);
   
   extgbdataset(strexitbarpos,barpos ) ;
   extgbdataset(strposition,position ) ;
  end
     //开空仓 
  if sss and extgbdata(strentrybarpos)<>barpos  then begin
   myentryprice := ma20-2*mindiff ;   
   position := -1 ;
   
                tbuyshort(1,ss,mkt);
               
                extgbdataset(strentrybarpos,barpos ) ;
   extgbdataset(strpreentryprice,myentryprice ) ;
   extgbdataset(strposition,position ) ;
  end
  
      goto continueline ;
 
      end  //if如果当前持有多头仓位的状态

 //如果以上3种情形都没有成立,则直接结束本次判断
 goto continueline ;

end //if如果当前棒是最后一根k线
 

//如果不是最后一根k线的情形
IF  NOT(ISLASTBAR)  THEN  BEGIN

   //如果当前是没有持仓的状态
if position=0   then begin
     //多头进场
 if bbb then begin
  myentryprice :=ma20+2*mindiff ;   
  //buy( 1,SS,MARKET);
  position := 1 ;
  buyorderthisbar := 1;
  
 end //if  
 
      //空头进场
 if sss  then begin   
  myentryprice := ma20-2*mindiff ;    
  //buyshort(1,SS,MARKET);
  position := -1 ;
  buyorderthisbar := 1;

 end 
      goto continueline ;
  
end  //if如果当前是没有持仓的状态


//如果当前持有空头仓位的状态
if position=-1    then begin

     //平空仓
 if bbb and buyorderthisbar=0 then begin
  myexitprice :=ma20+2*mindiff ;     
  //sellshort( 1,ss,MARKET);  
 end

     //开多仓 
 if bbb and  buyorderthisbar=0 then begin
   myentryprice := ma20+2*mindiff ; 
   //buy( 1,ss, MARKET);  
   position := 1 ;
   buyorderthisbar := 1;
 end
 
end  //if如果当前持有空头仓位的状态

//如果当前持有多头仓位的状态
if position=1   then begin

     //平多仓
 if sss and buyorderthisbar=0 then begin
  myexitprice :=ma20-2*mindiff ;     
  //sell( 1,ss,MARKET);  
 end

     //开空仓 
 if sss and  buyorderthisbar=0 then begin
   myentryprice := ma20-2*mindiff ; 
   //buyshort( 1,ss, MARKET);  
   position := -1 ;
   buyorderthisbar := 1;
 end
 
end  //if如果当前持有多头仓位的状态
END //IF不是最后一根k线的情形

//显示账户状态
continueline@ 资产:asset,linethick0;

if _debugout>0  and islastbar then begin

  DEBUGFILE2('D:\Debug\DEBUGFILE.TXT','POSITION=%.0f' ,POSITION,1) ;

end //if


 



查看使用道具详细信息
悬赏金币帖,要悬赏 0 个金币
 回到顶部
总数 29 1 2 3 下一页