【金字塔策略源码】突破策略

0
回复
7418
查看
[复制链接]

39

主题

6

回帖

214

积分

超级版主

积分
214
来源: 2020-3-8 07:18:30 显示全部楼层 |阅读模式
  1. runmode:0;

  2. input:period(70,5,90,5);
  3. input:initialstop(2,0,3,1),coststop(2,1,3,1),trailingstop(3,1,6,1);
  4. input:money(0,0,10,1);
  5. input:slippage(1,0,1,1);
  6. input:debug(0,0,1,1);

  7. variable:myasset=500000;
  8. variable:costprice=0,stopline=0;

  9. begin
  10. if stricmp(marketlabel,'sh')=0 then begin
  11.   commission:=0.001;
  12.   stamptax:=0.001;
  13.   transferfee:=0.001;
  14. end

  15. if stricmp(marketlabel,'sz')=0 then begin
  16.   commission:=0.001;
  17.   stamptax:=0.001;
  18.   transferfee:=0;
  19. end

  20. topband:=ref(hhv(high,period),1)+mindiff;

  21. atr:=ref(ma(tr,10),1);

  22. initialstopnum:=trimprice(initialstop*atr);
  23. coststopnum:=trimprice(coststop*atr);
  24. trailingstopnum:=trimprice(trailingstop*atr);
  25. slippagenum:=slippage*mindiff;
  26. end

  27. if holding=0 then begin
  28. price:=0;
  29. lots:=0;

  30. if barpos>=period and high>=topband then
  31.   price:=close+slippagenum;

  32. if price>0 then begin  
  33.   mycash:=cash(0);
  34.   
  35.   lots1:=intpart(mycash/(price*volunit))*volunit;   
  36.   
  37.   if money=0 then begin
  38.    lots:=lots1;
  39.   end else begin
  40.    lots2:=intpart(mycash*0.01*money/(initialstopnum*volunit))*volunit;
  41.    lots:=min(lots1,lots2);
  42.   end
  43. end  
  44.   
  45. if lots>=1 then begin
  46.   buy(1,lots,limitr,price);
  47.   
  48.   if workmode=1 then
  49.    tbuy(1,lots,limitr,price);
  50. end
  51. end

  52. if holding>0 then begin
  53. price:=0;
  54. lots:=holding;

  55. if initialstop>0 then begin
  56.   if stopline>0 and low<=stopline then
  57.    price:=close-slippagenum;
  58.    
  59.   if stopline=0 then begin
  60.    costprice:=trimprice((enterprice*(1+commission)+2*transferfee)/(1-commission-stamptax))+mindiff;
  61.    
  62.    stopline:=costprice-initialstopnum;
  63.   end
  64.    
  65.   if stopline<costprice and high-coststopnum>=costprice then
  66.    stopline:=costprice;
  67.   
  68.   if stopline>=costprice and high-trailingstopnum>stopline then
  69.    stopline:=high-trailingstopnum;   
  70. end

  71. if price>0 then begin
  72.   sell(1,lots,limitr,price);
  73.   costprice:=0;
  74.   stopline:=0;
  75.   
  76.   myasset:=asset;
  77.   
  78.   if workmode=1 then
  79.    tsell(1,lots,limitr,price);
  80. end
  81. end

  82. partline(debug=1 and holding=0,topband,colorred,1);

  83. if initialstop>0 then begin
  84. if holding>0 then begin
  85.   drawicon(stopline<costprice,stopline,11);
  86.   drawicon(stopline=costprice,stopline,12);
  87.   drawicon(stopline>costprice,stopline,10);
  88. end
  89. end

  90. if debug=1 then begin
  91. 盈亏:myasset,noaxis,colormagenta;      
  92. 收益:(myasset-500000)/500000,linethick0;
  93. 次数:totaltrade,linethick0;
  94. 胜率:percentwin,linethick0;
  95. 连亏:maxseqloss,linethick0;
  96. 连赢:maxseqwin,linethick0;
  97. end
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册
关注微信