[MC源码] [策略分享] 三兵连营策略

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

39

主题

6

回帖

214

积分

超级版主

积分
214
来源: 2020-5-30 14:15:37 显示全部楼层 |阅读模式
相隔一段时间,这次再来介绍一个趋势策略,用大家熟悉的布林通道所组成,**学习参考

策略原理:
模型通过红绿三兵进行形态识别、利用布林通道上下轨确定价格的相对位置、辅以布林中轨均线过滤及设定价格高低点突破作为开仓信号。出场采用之前的移动停利出场方式,可以自己拓展出场模式。

此策略未做任何优化,参数都是默认常用值,自己可以调整,适合商品趋势行情。

策略源码如下:
  1. inputs:
  2.         BollingerPrice( Close ),
  3.         TestPriceUBand( Close ),
  4.         TestPriceLBand( Close ),
  5.         Length( 20 ),
  6.         NumDevsUp( 2 ),
  7.         NumDevsDn( -2 ),
  8.         Displace( 0 ) ,
  9.         mm(10);
  10. variables:
  11.         var0( 0 ),
  12.         var1( 0 ),
  13.         var2( 0 ),
  14.         var3( 0 ) ;

  15. var0 = AverageFC( BollingerPrice, Length ) ;
  16. var1 = StandardDev( BollingerPrice, Length, 1 ) ;
  17. var3 = var0 + NumDevsUp * var1 ;
  18. var2 = var0 + NumDevsDn * var1 ;
  19. /////////////////////////////////////////////布林轨道

  20. condition1=CountIf(close>open,3)>=3;
  21. condition2=CountIf(close>close[1],3)>=3;
  22. condition3=CountIf(open>open[1],3)>=3;

  23. condition4=open>open[1] and open[1]>open[2]and close>close[1] and close[1]>close[2];

  24. condition10=CountIf(var3>var3[1],5)>=5;

  25. if condition1 and condition2 and condition3 and condition4
  26. and marketposition=0 and close>=Average(var0,mm) and condition10 then buy("BK") next bar at Highest(high,3) stop;
  27. ///////////////////////////////////////判别白三兵加boll轨道过滤进场

  28. condition5=CountIf(close<open,3)>=3;
  29. condition6=CountIf(close<close[1],3)>=3;
  30. condition7=CountIf(open<open[1],3)>=3;

  31. condition8=close<close[1] and close[1]<close[2] and open<open[1] and open[1]<open[2];

  32. condition11=CountIf(var3<var3[1],5)>=5;

  33. if condition5 and condition6 and condition7 and condition8
  34. and marketposition=0 and close<Average(var0,mm)  and condition11 then sellshort("SK") next bar at lowest(low,3) stop;
  35. ///////////////////////////////////判别黑三兵加boll过滤进场

  36. input:stoppoint(10);
  37. var:longstop(0),barHH(0);
  38. if barssinceentry=0 then begin
  39. longstop=minlist(low,low[1])-stoppoint;
  40. barHH=high;
  41. end;

  42. if high>barHH then barHH=high;
  43. if barssinceentry>0 then begin
  44. if c>barHH[1] then longstop=minlist(low,low[1])-stoppoint;
  45. end;

  46. if marketposition=1 then sell("EL") next bar at longstop stop ;
  47. input:stoppoint1(10);
  48. var:longstop1(0),barll(0);
  49. if barssinceentry=0 then begin
  50. longstop1=maxlist(high,high[1])+stoppoint;
  51. barll=low;
  52. end;

  53. if low<barll then barll=low;
  54. if barssinceentry>0 then begin
  55. if c<barll[1] then longstop1=maxlist(high,high[1])+stoppoint;
  56. end;

  57. if marketposition=-1 then buytocover("EX") next bar at longstop1 stop ;
  58. ////////////////////////////////////////////移动止盈出场
复制代码



回复

使用道具 举报

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