分享

金字塔超级日内组合策略源码[金字塔模型]

 今夕何夕758 2020-04-07

模型策略源码:

runmode:0;

input:waitperiodmins(30);

input:inittradesendtime(143000);

input:liqrevendtime(110000);

input:thrustprcnt1(0.3);

input:thrustprcnt2(0.6);

input:breakoutprcnt(0.25);

input:failedbreakoutprcnt(0.25);

input:protstopprcnt1(0.25);

input:protstopprcnt2(0.15);

input:protstopamt(3);

input:breakevenprcnt(0.5);

input:avgrnglength(10);

input:avgoclength(10);

variable:averagerange=0;

variable:averageocrange=0;

variable:cantrade=0;

variable:buyeasierday=false;

variable:selleasierday=false;

variable:buybopoint=0;

variable:sellbopoint=0;

variable:longbreakpt=0;

variable:shortbreakpt=0;

variable:longfbopoint=0;

variable:shortfbopoint=0;

variable:barcount=0;

variable:intrahigh=0;

variable:intralow=999999;

variable:buystoday=0;

variable:sellstoday=0;

variable:currtrdtype=0;

variable:longliqpoint=0;

variable:shortliqpoint=0;

variable:yesterdayocrrange=0;

variable:intratradehigh=0;

variable:intratradelow=999999;

//来源 www.cxh99.com

m1:=ref(ma(callstock(stklabel,vthigh,6,0)-callstock(stklabel,vtlow,6,0),10),1);

m2:=ref(ma(abs(callstock(stklabel,vtopen,6,0)-callstock(stklabel,vtclose,6,0)),10),1);

m3:=ref(llv(low,3),1);

m4:=ref(hhv(high,3),1);

if date>ref(date,1) then begin

 averagerange:=m1;

 yesterdayocrrange:=abs(open-close);

 averageocrange:=m2;

 cantrade:=0;

 if yesterdayocrrange<0.85*averageocrange then cantrade:=1;

 buyeasierday:=false;

 selleasierday:=false;

 if callstock(stklabel,vtclose,6,-1)<=callstock(stklabel,vtclose,6,-2) then buyeasierday:=true;

 if callstock(stklabel,vtclose,6,-1)>callstock(stklabel,vtclose,6,-2) then selleasierday:=true;

 if buyeasierday then begin

  buybopoint:=callstock(stklabel,vtopen,6,0) thrustprcnt1*averagerange;

  sellbopoint:=callstock(stklabel,vtopen,6,0)-thrustprcnt2*averagerange;

 end

 if selleasierday then begin

  sellbopoint:=callstock(stklabel,vtopen,6,0)-thrustprcnt1*averagerange;

  buybopoint:=callstock(stklabel,vtopen,6,0) thrustprcnt2*averagerange;

 end

 longbreakpt:=callstock(stklabel,vthigh,6,-1) breakoutprcnt*averagerange;

 shortbreakpt:=callstock(stklabel,vtlow,6,-1)-breakoutprcnt*averagerange;

 shortfbopoint:=callstock(stklabel,vthigh,6,-1)-failedbreakoutprcnt*averagerange;

 longfbopoint:=callstock(stklabel,vtlow,6,-1) failedbreakoutprcnt*averagerange;

 barcount:=0;

 intrahigh:=0;

 intralow:=999999;

 buystoday:=0;

 sellstoday:=0;

 currtrdtype:=0;

end

if high>intrahigh then intrahigh:=high;

if low

barcount:=barcount 1;

if barcount>waitperiodmins/datatype and cantrade=1 then begin

 if holding=0 then begin

  intratradehigh:=0;

  intratradelow:=999999;

 end

 if holding>0 then begin

  intratradehigh:=max(intratradehigh,high);

  buystoday:=1;

 end

 if holding<0 then begin

  intratradelow:=min(intratradelow,low);

  sellstoday:=1;

 end

 if buystoday=0 and time

  LBreakOut:buy(1,1,stop,buybopoint);

 if sellstoday=0 and time

  SBreakout:sellshort(1,1,stop,sellbopoint); 

 if intrahigh>longbreakpt and sellstoday=0 and time

  SfailedBO:sellshort(1,1,stop,shortfbopoint);

 if intralow

  BfeiledBO:buy(1,1,stop,longfbopoint); 

 if holding>0 then begin

  longliqpoint:=enterprice-protstopprcnt1*averagerange;

  longliqpoint:=min(longliqpoint,enterprice-protstopamt);

  if ref(holding,1)<0 and enterbars>=1 and ref(high,1)>=shortliqpoint and shortliqpoint

   currtrdtype:=-2;

  if currtrdtype=-2 then begin

   longliqpoint:=enterprice-protstopprcnt2*averagerange;

   longliqpoint:=min(longliqpoint,enterprice-protstopamt);

  end 

  if intratradehigh>=enterprice breakevenprcnt*averagerange then

   longliqpoint:=enterprice;

  if time>=inittradesendtime then

   longliqpoint:=max(longliqpoint,m3);

  if time<>enterprice and enterbars>=4 then begin

   LongLiqRev:sellshort(1,1,stop,longliqpoint);

  end else begin

   LongLiq:sell(1,1,stop,longliqpoint);

  end   

 end  

 if holding<0 then begin

  shortliqpoint:=enterprice protstopprcnt1*averagerange;

  shortliqpoint:=max(shortliqpoint,enterprice protstopamt);

  if ref(holding,1)<0 and enterbars>=1 and ref(low,1)longfbopoint then

   currtrdtype:=2;

  if currtrdtype=2 then begin

   shortliqpoint:=enterprice protstopprcnt2*averagerange;

   shortliqpoint:=max(shortliqpoint,enterprice protstopamt);

  end 

  if intratradelow<=enterprice-breakevenprcnt*averagerange then

   shortliqpoint:=enterprice;

  if time>=inittradesendtime then

   shortliqpoint:=min(shortliqpoint,m4);

  if time<>enterprice and enterbars>=4 then begin

   ShortLiqRev:buy(1,1,stop,shortliqpoint);

  end else begin

   ShortLiq:sellshort(1,1,stop,shortliqpoint);

  end   

 end

end

if time>=closetime(0) then begin

 sell(1,holding,limitr,close);

 sellshort(1,holding,limitr,close);

end

盈亏:asset-500000,noaxis,coloryellow,linethick2;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多