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


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → 海龟策略如何去掉加仓代码

   

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


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

主题:海龟策略如何去掉加仓代码

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


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/6/3 17:06:48    Post IP:180.169.30.6[只看该作者]

INPUT : T20(20,15,60,1) ;//长周期
INPUT : T10(10,10,30,1);//短周期
INPUT : ATRLEN(20,15,30,1) ;//波动周期
INPUT : POSNUM(1,1,20,1) ;//持仓手数
input:n(10,1,60,1),m(20,1,60,1),p(60,1,60,1);

MA10:=MA(CLOSE,n);
MA20:=MA(CLOSE,m);
MA60:=MA(CLOSE,p);




KD:=(CROSS(MA10,MA20) or (cross(ma10,ma60)) and ma10>=ma20) ;          //开多条件
PD:=CROSS(MA20,MA10);          //平多条件
KK:=(cross(ma20,ma10)  or (CROSS(MA60,MA10)) and ma10<=ma60);          //开空条件
PK:=CROSS(MA10,MA20);          //平空条件


平空:SELLSHORT(PK,1,THISCLOSE);                  //平空信号
开多:BUY(KD AND HOLDING=0,1,THISCLOSE);          //开多信号
平多:SELL(PD,1,THISCLOSE);                       //平多信号
开空:BUYSHORT(KK AND HOLDING=0,1,THISCLOSE);     //开空信号


持仓:holding,linethick0;
资产:asset,noaxis; 


金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

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


加好友 发短信
等级:论坛游民 帖子:127 积分:0 威望:0 精华:0 注册:2016/5/16 13:48:54
  发帖心情 Post By:2016/6/16 15:44:08    Post IP:113.99.227.147[只看该作者]

下面的公式导入时出现错误   帮我纠正下好吗老师

runmode:0;

input:money(0,0,5,1);
input:ratio(2,1,10,1);

variable:trend=0;
variable:callback=0;
variable:stoplossprice=0;
variable:takeprofitprice=0;
variable:daytradecounter=0;

if day>ref(day,1) then begin
 callback:=0;
 daytradecounter:=0;
 
 if close=open then
  trend:=0;
  
 if close>open then
  trend:=1;
  
 if close<open then
  trend:=-1; 
end

if trend=0 then begin
 if close>open then
  trend:=1;
 
 if close<open then
  trend:=-1; 
end

dist:=barslast(day>ref(day,1))+1;

highest:=ref(hhv(high,dist),1);
lowest:=ref(llv(low,dist),1);

if trend=1 and low<=lowest then
 trend:=-1;
 
if trend=-1 and high>=highest then
 trend:=1; 

dist1:=barslast(high<ref(high,1) and low<ref(low,1));
stoplossprice1:=ref(low,dist1);

dist2:=barslast(high>ref(high,1) and low>ref(low,1));
stoplossprice2:=ref(high,dist2);

if trend=1 and ref(high,1)<ref(high,3) and ref(high,2)<ref(high,3)  and ref(high,3)=highest then
 callback:=1;

if trend=-1 and ref(low,1)>ref(low,3) and ref(low,2)>ref(low,3)  and ref(low,3)=lowest then
 callback:=-1;
 
if holding=0 then begin
 myentryprice:=0;
 lots:=0;
 
 if daytradecounter=0 and dist>=4 and trend=1 and callback=1 and high>=highest+mindiff then 
  myentryprice:=max(open,highest+mindiff);  
 
 if myentryprice>0 then  begin 
  if dist1<=dist then
   stoplossprice:=stoplossprice1;
  else
   stoplossprice:=lowest;
   
  initialstopnum:=myentryprice-stoplossprice; 
  
  takeprofitprice:=myentryprice+initialstopnum*ratio;
    
  if money=0 then begin
   lots:=1;
  end else begin
   mycash:=cash(0);
   lots1:=intpart(mycash/(myentryprice*multiplier*taccount(41)));
   lots2:=intpart(mycash*(money/100)/(initialstopnum*multiplier));
   lots:=min(lots1,lots2);
  end
 end 
  
 if lots>=1 then begin
  buy(1,lots,limitr,myentryprice);
  daytradecounter:=1;
 end 
end  

if holding=0 then begin
 myentryprice:=0;
 lots:=0;
 
 if daytradecounter=0 and dist>=4 and trend=-1 and callback=-1 and low<=lowest-mindiff then 
  myentryprice:=min(open,lowest-mindiff);  
 
 if myentryprice>0 then  begin 
  if dist2<=dist then
   stoplossprice:=stoplossprice2;
  else
   stoplossprice:=highest;
   
  initialstopnum:=stoplossprice-myentryprice; 
  
  takeprofitprice:=myentryprice-initialstopnum*ratio;
    
  if money=0 then begin
   lots:=1;
  end else begin
   mycash:=cash(0);
   lots1:=intpart(mycash/(myentryprice*multiplier*taccount(41)));
   lots2:=intpart(mycash*(money/100)/(initialstopnum*multiplier));
   lots:=min(lots1,lots2);
  end
 end 
  
 if lots>=1 then begin
  buyshort(1,lots,limitr,myentryprice);
  daytradecounter:=1;
 end 
end

if holding>0 then begin
 myexitprice:=0;
 lots:=holding;
 
 if stricmp(marketlabel,'zj')=0 then begin
  if time>=151500 then
   myexitprice:=open;
 end else begin
  if time>=150000 then
   myexitprice:=open;
 end 
 
 if high>=takeprofitprice then
  myexitprice:=max(open,takeprofitprice);
 
 if low<=stoplossprice then
  myexitprice:=min(open,stoplossprice); 
  
 if myexitprice>0 then  
  sell(1,lots,limitr,myexitprice);
end

if holding<0 then begin
 myexitprice:=0;
 lots:=-holding;
 
 if stricmp(marketlabel,'zj')=0 then begin
  if time>=151500 then
   myexitprice:=open;
 end else begin
  if time>=150000 then
   myexitprice:=open;
 end 
 
 if low<=takeprofitprice then
  myexitprice:=min(open,takeprofitprice);
  
 if high>=stoplossprice then
  myexitprice:=max(open,stoplossprice); 
   
 if myexitprice>0 then  
  sellshort(1,lots,limitr,myexitprice);
end

drawicon(holding<>0,stoplossprice,11);
drawicon(holding<>0,takeprofitprice,10);

资产:asset,noaxis,linethick2;


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


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/6/16 15:46:20    Post IP:180.169.30.6[只看该作者]

runmode:0;

input:money(0,0,5,1);
input:ratio(2,1,10,1);

variable:trend1=0;
variable:callback=0;
variable:stoplossprice=0;
variable:takeprofitprice=0;
variable:daytradecounter=0;

if day>ref(day,1) then begin
 callback:=0;
 daytradecounter:=0;
 
 if close=open then
  trend1:=0;
 
 if close>open then
  trend1:=1;
 
 if close<open then
  trend1:=-1;
end

if trend1=0 then begin
 if close>open then
  trend1:=1;
 
 if close<open then
  trend1:=-1;
end

dist:=barslast(day>ref(day,1))+1;

highest:=ref(hhv(high,dist),1);
lowest:=ref(llv(low,dist),1);

if trend1=1 and low<=lowest then
 trend1:=-1;
 
if trend1=-1 and high>=highest then
 trend1:=1;

dist1:=barslast(high<ref(high,1) and low<ref(low,1));
stoplossprice1:=ref(low,dist1);

dist2:=barslast(high>ref(high,1) and low>ref(low,1));
stoplossprice2:=ref(high,dist2);

if trend1=1 and ref(high,1)<ref(high,3) and ref(high,2)<ref(high,3)  and ref(high,3)=highest then
 callback:=1;

if trend1=-1 and ref(low,1)>ref(low,3) and ref(low,2)>ref(low,3)  and ref(low,3)=lowest then
 callback:=-1;
 
if holding=0 then begin
 myentryprice:=0;
 lots:=0;
 
 if daytradecounter=0 and dist>=4 and trend1=1 and callback=1 and high>=highest+mindiff then
  myentryprice:=max(open,highest+mindiff); 
 
 if myentryprice>0 then  begin
  if dist1<=dist then
   stoplossprice:=stoplossprice1;
  else
   stoplossprice:=lowest;
  
  initialstopnum:=myentryprice-stoplossprice;
 
  takeprofitprice:=myentryprice+initialstopnum*ratio;
   
  if money=0 then begin
   lots:=1;
  end else begin
   mycash:=cash(0);
   lots1:=intpart(mycash/(myentryprice*multiplier*taccount(41)));
   lots2:=intpart(mycash*(money/100)/(initialstopnum*multiplier));
   lots:=min(lots1,lots2);
  end
 end
 
 if lots>=1 then begin
  buy(1,lots,limitr,myentryprice);
  daytradecounter:=1;
 end
end 

if holding=0 then begin
 myentryprice:=0;
 lots:=0;
 
 if daytradecounter=0 and dist>=4 and trend1=-1 and callback=-1 and low<=lowest-mindiff then
  myentryprice:=min(open,lowest-mindiff); 
 
 if myentryprice>0 then  begin
  if dist2<=dist then
   stoplossprice:=stoplossprice2;
  else
   stoplossprice:=highest;
  
  initialstopnum:=stoplossprice-myentryprice;
 
  takeprofitprice:=myentryprice-initialstopnum*ratio;
   
  if money=0 then begin
   lots:=1;
  end else begin
   mycash:=cash(0);
   lots1:=intpart(mycash/(myentryprice*multiplier*taccount(41)));
   lots2:=intpart(mycash*(money/100)/(initialstopnum*multiplier));
   lots:=min(lots1,lots2);
  end
 end
 
 if lots>=1 then begin
  buyshort(1,lots,limitr,myentryprice);
  daytradecounter:=1;
 end
end

if holding>0 then begin
 myexitprice:=0;
 lots:=holding;
 
 if stricmp(marketlabel,'zj')=0 then begin
  if time>=151500 then
   myexitprice:=open;
 end else begin
  if time>=150000 then
   myexitprice:=open;
 end
 
 if high>=takeprofitprice then
  myexitprice:=max(open,takeprofitprice);
 
 if low<=stoplossprice then
  myexitprice:=min(open,stoplossprice);
 
 if myexitprice>0 then 
  sell(1,lots,limitr,myexitprice);
end

if holding<0 then begin
 myexitprice:=0;
 lots:=-holding;
 
 if stricmp(marketlabel,'zj')=0 then begin
  if time>=151500 then
   myexitprice:=open;
 end else begin
  if time>=150000 then
   myexitprice:=open;
 end
 
 if low<=takeprofitprice then
  myexitprice:=min(open,takeprofitprice);
 
 if high>=stoplossprice then
  myexitprice:=max(open,stoplossprice);
  
 if myexitprice>0 then 
  sellshort(1,lots,limitr,myexitprice);
end

drawicon(holding<>0,stoplossprice,11);
drawicon(holding<>0,takeprofitprice,10);

资产:asset,noaxis,linethick2;



金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

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


加好友 发短信
等级:论坛游民 帖子:127 积分:0 威望:0 精华:0 注册:2016/5/16 13:48:54
  发帖心情 Post By:2016/6/16 16:40:21    Post IP:113.71.128.153[只看该作者]

老师您好下面策略帮我修改一下好吗

 runmode:0;

{ 策略名称:PCB 
 交易品种:糖 
交易周期:5分钟 
 入市策略:通道突破 
 风险控制:收盘平仓 
 资金管理:1手  }

 input:period(20,5,100,5);

 variable:myasset=30000; 
 
 entertime:=time>=092500 and time<=145500; 
 exittime:=time>=150000; 
 
 highest:=ref(hhv(high,period),1); 
 lowest:=ref(llv(low,period),1); 
 
 buycond:=entertime and high>=highest; 
 buyprice:=max(open,highest); 
 
 buyshortcond:=entertime and low<=lowest; 
 buyshortprice:=min(open,lowest); 
 
 if holding=0 and buycond then begin 
 buy(1,1,limitr,buyprice); 
 end 
 
 if holding=0 and buyshortcond then begin 
 buyshort(1,1,limitr,buyshortprice); 
 end 
 
 if holding>0 and exittime then begin 
 sell(1,holding,limitr,close); 
 end 
 
 if holding<0 and exittime then begin 
 sellshort(1,holding,limitr,close); 
 end 
 
 if exittime then 
 myasset:=asset; 
 
 资产:myasset,noaxis,colormagenta; 
 次数:totaltrade,linethick0; 
 收益:(myasset-30000)/30000,linethick0; 
 胜率:percentwin,linethick0; 
 连亏:maxseqloss,linethick0; 
 连赢:maxseqwin,linethick0; 



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


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/6/16 16:50:58    Post IP:180.173.43.114[只看该作者]

input:period1(20,5,100,5);

 variable:myasset=30000;
 
 entertime:=time>=092500 and time<=145500;
 exittime:=time>=150000;
 
 highest:=ref(hhv(high,period),1);
 lowest:=ref(llv(low,period),1);
 
 buycond:=entertime and high>=highest;
 buyprice:=max(open,highest);
 
 buyshortcond:=entertime and low<=lowest;
 buyshortprice:=min(open,lowest);
 
 if holding=0 and buycond then begin
 buy(1,1,limitr,buyprice);
 end
 
 if holding=0 and buyshortcond then begin
 buyshort(1,1,limitr,buyshortprice);
 end
 
 if holding>0 and exittime then begin
 sell(1,holding,limitr,close);
 end
 
 if holding<0 and exittime then begin
 sellshort(1,holding,limitr,close);
 end
 
 if exittime then
 myasset:=asset;
 
 资产:myasset,noaxis,colormagenta;
 次数:totaltrade,linethick0;
 收益:(myasset-30000)/30000,linethick0;
 胜率:percentwin,linethick0;
 连亏:maxseqloss,linethick0;
 连赢:maxseqwin,linethick0;



金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

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


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/6/16 16:51:43    Post IP:180.173.43.114[只看该作者]

这两个策略的问题是一样的,定义好的变量是系统的保留字符,所以导致了编译不通过,我的解决办法是在这些变量结尾处加个1就行。

用户可以自行处理一下



金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

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


加好友 发短信
等级:论坛游民 帖子:127 积分:0 威望:0 精华:0 注册:2016/5/16 13:48:54
  发帖心情 Post By:2016/6/16 16:59:55    Post IP:113.71.128.153[只看该作者]

老师还是不行哦还是不通过

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


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/6/16 17:08:16    Post IP:180.173.198.10[只看该作者]

没问题,你直接新建一个指标,把我的代码贴进去

不要在原来的里面改


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


金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

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


加好友 发短信
等级:论坛游民 帖子:127 积分:0 威望:0 精华:0 注册:2016/5/16 13:48:54
  发帖心情 Post By:2016/6/16 17:11:52    Post IP:113.71.128.153[只看该作者]

老师可以啦 呵呵  还有一个tb公式帮我修改成金字塔公式好吗?
//TB公式代码如下
Params
        Numeric nMins(30);                // N分钟的突破
    Numeric nOffset(3);                // 突破式的价格偏移
Vars
        NumericSeries HighestOf30Min;
    NumericSeries lowestOf30Min;
    Numeric myPrice;
    Numeric MinPoint;
    Numeric lots(1);
Begin
        MinPoint = MinMove*PriceScale;
        If(Date <> Date[1])
        {
                HighestOf30Min = High;
                lowestOf30Min = Low;
        }Else If(Time < 0.0900+nMins*0.0001)
        {
                HighestOf30Min = max(high,HighestOf30Min[1]);
                lowestOf30Min = min(Low,lowestOf30Min[1]);
        }Else
        {
                HighestOf30Min = HighestOf30Min[1];
                lowestOf30Min = lowestOf30Min[1];
        }
        
        If(High >= HighestOf30Min + nOffset*MinPoint && MarketPosition != 1)
        {
                myPrice = HighestOf30Min + nOffset*MinPoint;
                If(Open > myPrice) myPrice = Open;
                Buy(lots,myPrice);
        }

        If(Low <= lowestOf30Min - nOffset*MinPoint && MarketPosition != -1)
        {
                myPrice = lowestOf30Min - nOffset*MinPoint;
                If(Open < myPrice) myPrice = Open;
                SellShort(lots,myPrice);
        }

        If(Time >= 0.1459)
        {
                Sell(lots,Open);
                BuyToCover(lots,Open);
        }
End
 
/////////////////////////////////////////////////////////////////////////////////////
//下面为金字塔代码 (感谢轮回)

INPUT:NMIN(30,10,60,10);     //设置参数
INPUT:NOFFSET(3,1,20,1);     //设置参数
INPUT:LOTS(1,1,1000,1);      //设置参数
CYC:=BARSLAST(DATE>REF(DATE,1))+1;                                                    //统计日内K线数
HIGHESTOF30MIN:=VALUEWHEN(TIME<=90000+NMIN*100,HHV(H,CYC));        {在从开盘到设定时间(默认参数开盘30分)内保存当天最高价}
LOWESTOF30MIN:=VALUEWHEN(TIME<=90000+NMIN*100,LLV(L,CYC));         {在从开盘到设定时间(默认参数开盘30分)内保存当天最低价}
IF HIGH >= HIGHESTOF30MIN + NOFFSET*MINDIFF AND HOLDING<=0  THEN  {如果最高价突破设定时间内的前高加设定偏移并且目前没有多单,那么}
BEGIN
 MYPRICE: = HIGHESTOF30MIN + NOFFSET*MINDIFF;                                     {预设进场价.既等于设定时间内的前高加设定偏移}
 IF OPEN > MYPRICE THEN                                                                            {如果开盘价大于预设进场价,那么奋不顾身闯进去,(注:这是移植的,原设计并不一定完美,这时可能不是那么好成交的,我也不必多费唇舌了).}
 BEGIN
  MYPRICE: = OPEN;
  SELLSHORT(HOLDING<0,0,LIMITR,MYPRICE);                                                {如果有空单先平}
  BUY(HOLDING=0,LOTS,LIMITR,MYPRICE);                                                     {如果没有多单则以开盘价开多LOTS手}
 END
END
IF LOW <= LOWESTOF30MIN - NOFFSET*MINDIFF AND HOLDING>=0  THEN      {以下开空部分同上,只不过方向相反}
BEGIN
 MYPRICE: = LOWESTOF30MIN - NOFFSET*MINDIFF;
 IF OPEN < MYPRICE THEN
 BEGIN
  MYPRICE: = OPEN;
  SELL(HOLDING>0,0,LIMITR,MYPRICE);
  BUYSHORT(HOLDING=0,LOTS,LIMITR,MYPRICE);
 END
END
IF TIME >= 145900 THEN                                                                                {收盘平仓}
BEGIN
 SELL(HOLDING>0,0,LIMITR,OPEN);
 SELLSHORT(HOLDING<0,0,LIMITR,OPEN);
END

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


加好友 发短信
等级:论坛游民 帖子:127 积分:0 威望:0 精华:0 注册:2016/5/16 13:48:54
  发帖心情 Post By:2016/6/16 17:13:13    Post IP:113.71.128.153[只看该作者]

老师可以啦 呵呵  还有一个tb公式帮我修改成金字塔公式好吗?
//TB公式代码如下
Params
        Numeric nMins(30);                // N分钟的突破
    Numeric nOffset(3);                // 突破式的价格偏移
Vars
        NumericSeries HighestOf30Min;
    NumericSeries lowestOf30Min;
    Numeric myPrice;
    Numeric MinPoint;
    Numeric lots(1);
Begin
        MinPoint = MinMove*PriceScale;
        If(Date <> Date[1])
        {
                HighestOf30Min = High;
                lowestOf30Min = Low;
        }Else If(Time < 0.0900+nMins*0.0001)
        {
                HighestOf30Min = max(high,HighestOf30Min[1]);
                lowestOf30Min = min(Low,lowestOf30Min[1]);
        }Else
        {
                HighestOf30Min = HighestOf30Min[1];
                lowestOf30Min = lowestOf30Min[1];
        }
        
        If(High >= HighestOf30Min + nOffset*MinPoint && MarketPosition != 1)
        {
                myPrice = HighestOf30Min + nOffset*MinPoint;
                If(Open > myPrice) myPrice = Open;
                Buy(lots,myPrice);
        }

        If(Low <= lowestOf30Min - nOffset*MinPoint && MarketPosition != -1)
        {
                myPrice = lowestOf30Min - nOffset*MinPoint;
                If(Open < myPrice) myPrice = Open;
                SellShort(lots,myPrice);
        }

        If(Time >= 0.1459)
        {
                Sell(lots,Open);
                BuyToCover(lots,Open);
        }
End
 
/////////////////////////////////////////////////////////////////////////////////////
//下面为金字塔代码 (感谢轮回)

INPUT:NMIN(30,10,60,10);     //设置参数
INPUT:NOFFSET(3,1,20,1);     //设置参数
INPUT:LOTS(1,1,1000,1);      //设置参数
CYC:=BARSLAST(DATE>REF(DATE,1))+1;                                                    //统计日内K线数
HIGHESTOF30MIN:=VALUEWHEN(TIME<=90000+NMIN*100,HHV(H,CYC));        {在从开盘到设定时间(默认参数开盘30分)内保存当天最高价}
LOWESTOF30MIN:=VALUEWHEN(TIME<=90000+NMIN*100,LLV(L,CYC));         {在从开盘到设定时间(默认参数开盘30分)内保存当天最低价}
IF HIGH >= HIGHESTOF30MIN + NOFFSET*MINDIFF AND HOLDING<=0  THEN  {如果最高价突破设定时间内的前高加设定偏移并且目前没有多单,那么}
BEGIN
 MYPRICE: = HIGHESTOF30MIN + NOFFSET*MINDIFF;                                     {预设进场价.既等于设定时间内的前高加设定偏移}
 IF OPEN > MYPRICE THEN                                                                            {如果开盘价大于预设进场价,那么奋不顾身闯进去,(注:这是移植的,原设计并不一定完美,这时可能不是那么好成交的,我也不必多费唇舌了).}
 BEGIN
  MYPRICE: = OPEN;
  SELLSHORT(HOLDING<0,0,LIMITR,MYPRICE);                                                {如果有空单先平}
  BUY(HOLDING=0,LOTS,LIMITR,MYPRICE);                                                     {如果没有多单则以开盘价开多LOTS手}
 END
END
IF LOW <= LOWESTOF30MIN - NOFFSET*MINDIFF AND HOLDING>=0  THEN      {以下开空部分同上,只不过方向相反}
BEGIN
 MYPRICE: = LOWESTOF30MIN - NOFFSET*MINDIFF;
 IF OPEN < MYPRICE THEN
 BEGIN
  MYPRICE: = OPEN;
  SELL(HOLDING>0,0,LIMITR,MYPRICE);
  BUYSHORT(HOLDING=0,LOTS,LIMITR,MYPRICE);
 END
END
IF TIME >= 145900 THEN                                                                                {收盘平仓}
BEGIN
 SELL(HOLDING>0,0,LIMITR,OPEN);
 SELLSHORT(HOLDING<0,0,LIMITR,OPEN);
END

 回到顶部
总数 109 上一页 1 2 3 4 5 6 7 8 9 10 下一页 ..11