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


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → 收盘前平仓

   

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


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

主题:收盘前平仓

美女呀,离线,留言给我吧!
jiangsen
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:黑侠 帖子:992 积分:4305 威望:0 精华:0 注册:2012/8/3 10:50:38
收盘前平仓  发帖心情 Post By:2012/9/14 20:05:35    Post IP:211.95.61.35[只看该作者]

//声明参数
Input : T20(20,15,60,1) ;
Input : T10(10,10,30,1);
Input : ATRLen(20,15,30,1) ;
Input : PosNum(1,1,20,1) ;

//声明变量
nt := 1 ;     //调试信息带时间戳
BuyOrderThisBar := 0 ;  //当前Bar有过交易

VARIABLE : _DEBUG = 1 ;     //是否输出前台交易指令
VARIABLE : _TDEBUG = 1 ;    //是否输出后台交易指令
VARIABLE : _DEBUGOUT = 0 ;    //是否输出后台交易的调试信息

VARIABLE : myEntryPrice =0 ;   //开仓价格
VARIABLE : myExitPrice =0 ;   //平仓价格

VARIABLE : TurtleUnits=0 ;   //交易单位
VARIABLE : Position=0 ;   //仓位状态
//0表示没有仓位,1表示持有多头, -1表示持有空头

VARIABLE : T20Hi=Close ;   //20周期的高点
VARIABLE : T20Lo=Close ;   //20周期的低点

VARIABLE : T10Hi=Close ;   //10周期的高点
VARIABLE : T10Lo=Close ;   //10周期的低点

//准备需要计算的变量
T20Hi := ref(hhv(h,T20),1) ;
T20Lo := ref(llv(l,T20),1) ;

T10Hi := ref(hhv(h,T10),1) ;
T10Lo := ref(llv(l,T10),1) ;

AvgTR :=  ref(MA(TR,ATRLen),1) ;

//开始执行时 初始化数据
If BARPOS=1 Then Begin
 //Position := 0 ;

End //If

//如果当前是没有持仓的状态
If Position=0 and BARPOS>T20 and h>l Then Begin

 //建立多头进场条件
 Long := h > T20Hi ;
 
 //多头进场
 if Long then begin
  myEntryPrice := IF(Open>T20Hi+MINDIFF ,Open ,T20Hi+MINDIFF ) ;   
  buy( _DEBUG,PosNum,limitr,myEntryPrice);
  Position := 1 ;
  TurtleUnits := 1 ;
  N := AvgTR ;
  BuyOrderThisBar := 1;

 end //if


 //建立空头进场条件
 Short := l < T20Lo ;
 
 //空头进场
 if Short and Position=0 then begin   
  myEntryPrice := IF(Open<T20Lo-MINDIFF ,Open ,T20Lo-MINDIFF ) ;   
  buyshort( _DEBUG,PosNum,limitr,myEntryPrice);
  Position := -1 ;
  TurtleUnits := 1 ;
  N := AvgTR ;
  BuyOrderThisBar := 1;

 end
 
 //不要跳转,让程序检查同一根K线是否可以加仓
 //Goto ContinueLine ;
 
End  //If


//如果当前持有多头仓位的状态

If Position=1 and BARPOS>T20 and h>l Then Begin

 //多头加仓条件
 
 While (High>myEntryPrice+0.5*N) and TurtleUnits<4 Do Begin
  myEntryPrice := IF(Open>myEntryPrice+0.5*N ,Open ,myEntryPrice+0.5*N ) ;
  myEntryPrice := Ceiling(myEntryPrice/MINDIFF)*MINDIFF ; 
  buy( _DEBUG, PosNum, limitr, myEntryPrice);
  TurtleUnits := TurtleUnits+1 ;
  BuyOrderThisBar := 1;

 End //While 
 
 //建立多头离场条件
 LongX1 := (low < T10Lo)  ;
 
 if LongX1 and BuyOrderThisBar=0 then begin
  myExitPrice := IF(Open<T10Lo-MINDIFF ,Open ,T10Lo-MINDIFF ) ;   
  sell( _DEBUG ,0,limitr,myExitPrice);
  Position := 0 ;
  TurtleUnits := 0 ;
 end

 //建立多头止损条件
 LongX2 := (Low<myEntryPrice-2*N)  ;

 if LongX2 and Position=1 and BuyOrderThisBar=0 then begin
  myExitPrice := IF(Open<myEntryPrice-2*N ,Open ,myEntryPrice-2*N ) ;  
  myExitPrice := Floor(myExitPrice/MINDIFF)*MINDIFF ; 
  sell( _DEBUG ,0,limitr,myExitPrice);
  Position := 0 ;
  TurtleUnits := 0 ;
 end

 Goto ContinueLine ;

End  //If


//如果当前持有空头仓位的状态

If Position = -1 and BARPOS>T20 and h>l Then Begin

 //空头加仓条件
 
 While (Low<myEntryPrice-0.5*N) and TurtleUnits<4 Do Begin
  myEntryPrice := IF(Open<myEntryPrice-0.5*N ,Open ,myEntryPrice-0.5*N ) ;   
  myEntryPrice := Floor(myEntryPrice/MINDIFF)*MINDIFF ; 
  buyshort( _DEBUG,PosNum, limitr, myEntryPrice);
  TurtleUnits := TurtleUnits+1 ;
  BuyOrderThisBar := 1;
 End //If 


 //建立空头离场条件
 ShortX1 := h > T10Hi  ;

 if ShortX1 and BuyOrderThisBar=0 then begin
  myExitPrice := IF(Open>T10Hi+MINDIFF ,Open ,T10Hi+MINDIFF ) ;   
  sellshort( _DEBUG,0,limitr,myExitPrice);
  Position := 0 ;
  TurtleUnits := 0 ;
 end

 //建立空头止损条件
 ShortX2 := High > myEntryPrice + 2*N  ;

 if ShortX2 and Position = -1 and BuyOrderThisBar=0  then begin
  myExitPrice := IF(Open>myEntryPrice+2*N ,Open ,myEntryPrice+2*N ) ;   
  myExitPrice := Ceiling(myExitPrice/MINDIFF)*MINDIFF ; 
  sellshort( _DEBUG,0,limitr,myExitPrice);
  Position := 0 ;
  TurtleUnits := 0 ;
 end

End  //If


//显示账户状态
ContinueLine@ 资产:ASSET,LINETHICK0;
可用现金:CASH(0),LINETHICK0;
Pos:HOLDING,LINETHICK0;
交易次数:TOTALDAYTRADE, LINETHICK0 ;

If _DEBUGOUT>0 Then Begin

 DEBUGFILE2('c:\debugfile.txt','BarPos=%.0f' ,BARPOS,nt ) ;
 DEBUGFILE2('c:\debugfile.txt','T20Hi=%.2f' ,T20Hi ,nt) ;
 DEBUGFILE2('c:\debugfile.txt','N=%.2f' ,N ,nt) ;
 DEBUGFILE2('c:\debugfile.txt','Close=%.2f' ,C ,nt) ;
 DEBUGFILE2('c:\debugfile.txt','Position=%.0f' ,Position,nt ) ;
 DEBUGFILE2('c:\debugfile.txt','TurtleUnits=%.0f' ,TurtleUnits,nt ) ;
 DEBUGFILE2('c:\debugfile.txt','myEntryPrice=%.0f' ,myEntryPrice ,nt) ;
 DEBUGFILE2('c:\debugfile.txt','myExitPrice=%.0f' ,myExitPrice ,nt) ;
 
End //If

 

想让这个系统每天收盘前平仓,该在什么地方添加什么语句呢?


 回到顶部