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


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → [求助]求高人将下面的程序改成适合在金字塔中运行的语句

   

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


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

主题:[求助]求高人将下面的程序改成适合在金字塔中运行的语句

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


加好友 发短信
等级:新手上路 帖子:25 积分:156 威望:0 精华:0 注册:2010/12/22 16:29:24
[求助]求高人将下面的程序改成适合在金字塔中运行的语句  发帖心情 Post By:2011/2/22 9:43:11    Post IP:118.132.166.236[只看该作者]

以下程序是交易开拓中的程序代码,我试着自己改写过,但总存在大大小小的问题,求高人帮忙改写以下,感激不尽!

Params
 Numeric PercentOfRange(0.3);   //params是定义参数,相当于INPUT,NUMERIC表示数值型的//
 Numeric MinRange(0.2);
 Numeric StopLossSet(0.5);
 Numeric TrailingStart(0.8);
 Numeric TrailingStop(0.5);
Vars                                   
 
NumericSeries DayOpen;             
                                             //Vars是申明变量,相当于Variable//  Numeric MinPoint; Numeric preDayHigh;

 Numeric preDayLow; 
 NumericSeries preDayRange;
 Numeric UpperBand;
 Numeric LowerBand;
 NumericSeries HigherAfterEntry;
 NumericSeries LowerAfterEntry;
 
 BoolSeries  bLongStoped;             //boolseries是布尔型,返回值是false或者true,这里初值都是false//
 BoolSeries  bShortStoped;

 Numeric StopLine;
 Numeric MyPrice;
Begin                              //begin表示主程序开始//
  preDayHigh = HighD(1);  //HIGHD(1)表示前一天的最高价,LOWD(1)表示前一天的最低价,该程序一般用在分钟线上,这相当于跨周期取数据//    preDayLow = LowD(1);
 If(Date!=Date[1])           //date[1]相当于金字塔中的REF(DATE,1)// 

 {
  DayOpen = Open;
  preDayRange = preDayHigh - preDayLow;
  If(preDayRange < Open*MinRange*0.01) preDayRange = Open*MinRange*0.01;  
 }Else
 {
  DayOpen = DayOpen[1];
  preDayRange = preDayRange[1];
  bLongStoped = bLongStoped[1];
  bShortStoped = bShortStoped[1];
  
  If(BarsSinceEntry == 1)     //BarsSinceEntry相当于金字塔中的ENTERBARS//
  {
   HigherAfterEntry = AvgEntryPrice;      //AvgEntryPrice相当于金字塔中的AVGENTERPRICE//
   LowerAfterEntry = HigherAfterEntry;
  }Else If(BarsSinceEntry > 1)
  {
   HigherAfterEntry = max(HigherAfterEntry[1],High[1]);  //HIGH[1]表示向前引用1个周期的数据,同REF//
   
LowerAfterEntry = min(LowerAfterEntry[1],Low[1]);
  }Else
  {
   HigherAfterEntry = HigherAfterEntry[1];
   LowerAfterEntry = LowerAfterEntry[1];
  }
 }
 UpperBand = DayOpen + preDayRange*PercentOfRange;
 LowerBand = DayOpen - preDayRange*PercentOfRange;
 
 // 多头开仓
 If(MarketPosition==0 && High>=UpperBand && Time < 140000 && bLongStoped==False)

                                                                                                             //MarketPosition==0,表示当前持仓为0,可同于holding//
 {
  MyPrice = UpperBand;
  If(Open > MyPrice) MyPrice = Open;
  Buy(1,MyPrice);                             //buy开仓,以价格myprice开一手//  

  bLongStoped = False;
    Return;
 }
 // 空头开仓
 If(MarketPosition==0 && Low<=LowerBand && Time < 140000&& bShortStoped==False)
 {
  MyPrice = LowerBand;
  If(Open < MyPrice) MyPrice = Open;
  SellShort(1,MyPrice);                    //sellshort开空头,相当于金子塔中的buyshort//
    bShortStoped = False;  
  Return;
 }
 
 // 止损平仓
 If(MarketPosition==1)      //相当于holding>0//
 {
  If(HigherAfterEntry >= AvgEntryPrice + DayOpen*TrailingStart*0.01)//跟踪
  {
   StopLine = HigherAfterEntry - DayOpen*TrailingStop*0.01;
  }Else // 止损
  {
   StopLine = UpperBand-DayOpen*StopLossSet*0.01;
  }
  
  If(Low <= StopLine)
  {
   MyPrice = StopLine;
   If(Open < MyPrice) MyPrice = Open;
   Sell(1,MyPrice);                 
   bLongStoped = True;
   bShortStoped = False;  
  }
 }Else If(MarketPosition==-1)   //相当于holding<0//
 {
  If(LowerAfterEntry <= AvgEntryPrice - DayOpen*TrailingStart*0.01)//跟踪
  {
   StopLine = LowerAfterEntry + DayOpen*TrailingStop*0.01;
  }Else // 止损
  {
   StopLine = LowerBand+DayOpen*StopLossSet*0.01;
  }
  
  If(High >= StopLine)
  {
   MyPrice = StopLine;
   If(Open > MyPrice) MyPrice = Open;
   BuyToCover(1,MyPrice);       // BuyToCover平空头,相当于sellshort//
   bLongStoped = False;
   bShortStoped = True;     
  }
 }

 // 收盘平仓
 If(Time >=145000)
 {
  Sell(1,Open);
  BuyToCover(1,Open);    
//以开盘价全部平仓//
 }
End                               END表示程序结束

[此贴子已经被作者于2011-2-22 10:05:05编辑过]

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


加好友 发短信
等级:管理员 帖子:7302 积分:32559 威望:1000 精华:45 注册:2003/12/30 16:34:32
  发帖心情 Post By:2011/2/22 9:49:07    Post IP:58.246.57.26[只看该作者]

格式太乱了,请用IE浏览器登录金字塔论坛

 回到顶部
美女呀,离线,留言给我吧!
ppliu
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:25 积分:156 威望:0 精华:0 注册:2010/12/22 16:29:24
  发帖心情 Post By:2011/2/22 10:05:49    Post IP:118.132.166.236[只看该作者]

重新弄过了,您在瞅瞅,谢谢哈!

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


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2011/2/22 12:06:45    Post IP:123.118.94.16[只看该作者]

带跟踪止损的区间突破系统


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


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2011/2/22 13:23:53    Post IP:123.118.94.16[只看该作者]

runmode:0;

input:percentOfRange(0.3,0.1,1,0.1);
input:minRange(0.2,0.1,1,0.1);
input:stopLossSet(0.5,0.1,1,0.1);
input:trailingStart(0.8,0.1,1,0.1);
input:trailingStop(0.5,0.1,1,0.1);

variable:longStopped=false;
variable:shortStopped=false;
variable:stopLine=0;

preDayHigh:=callstock(stklabel,vthigh,6,-1);
preDayLow:=callstock(stklabel,vtlow,6,-1);

dayOpen:=valuewhen(date<>ref(date,1),open);
preDayRange:=preDayHigh-preDayLow;

if preDayRange<dayOpen*minRange*0.01 then
 preDayRange:=dayOpen*minRange*0.01;

upperBand:=trimprice(dayOpen+preDayRange*percentOfRange);
lowerBand:=trimprice(dayOpen-preDayRange*percentOfRange);

enterTime:=time>=09100 and time<=140000;
exitTime:=time>=145000;

longCond:=enterTime and high>=upperBand and not(longStopped);
longPrice:=max(upperBand,open);

shortCond:=enterTime and low<=lowerBand and not(shortStopped);
shortPrice:=min(lowerBand,open);

if holding=0 then begin
 if longCond then begin
  buy(1,1,limitr,longPrice);
  longStopped:=true;
 end 
end

if holding=0 then begin
 if shortCond then begin
  buyshort(1,1,limitr,shortPrice);
  shortStopped:=true;
 end
end

higherAfterEntry:=ref(hhv(high,enterbars),1);
lowerAfterEntry:=ref(llv(low,enterbars),1);

if holding>0 then begin
 if higherAfterEntry>=avgenterprice+dayOpen*trailingStart*0.01 then
  stopline:=higherAfterEntry-dayOpen*trailingStop*0.01;
 else
  stopline:=upperBand-dayOpen*stopLossSet*0.01;
 
 if low<=stopLine then begin
  sell(1,holding,limitr,min(stopLine,open));
  longStopped:=true;  
  shortStopped:=false;
 end 
 
 if time>=exitTime then
  sell(1,holding,limitr,open); 
end

if holding<0 then begin
 if lowerAfterEntry<=avgenterprice-dayOpen*trailingStart*0.01 then
  stopline:=lowerAfterEntry+dayOpen*trailingStop*0.01;
 else
  stopline:=lowerBand+dayOpen*stopLossSet*0.01;
 
 if high>=stopLine then begin
  sellshort(1,holding,limitr,max(stopLine,open));
  shortStopped:=true;
  longStopped:=false;
 end 
 
 if time>=exitTime then
  sellshort(1,holding,limitr,open); 
end
 

[此贴子已经被作者于2011-2-22 14:10:11编辑过]

 回到顶部
美女呀,离线,留言给我吧!
ppliu
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:25 积分:156 威望:0 精华:0 注册:2010/12/22 16:29:24
  发帖心情 Post By:2011/2/24 9:24:29    Post IP:118.132.166.236[只看该作者]

谢谢你哈!不过我将您改写的程序调试过,为什么开仓平仓都在同一根bar上呢,好像有点问题啊?

 回到顶部