[MC源码] [策略分享] 趋势策略-三均线利剑

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

87

主题

6

回帖

1237

积分

超级版主

积分
1237
来源: 2020-5-31 15:18:55 显示全部楼层 |阅读模式
近来欧美股市的波动非常大啊,伊波拉病毒也蠢蠢欲动.....不知道会不会影响到咱们中国,也因此,策略天地在此介绍一个趋势型的策略,让读者们试试,策略优点主要在动态出场,进场随意写的,需要靠用户优化

策略适用商品:  a  h' b- q$ f: e/ [
趋势性较好的商品。下图测试商品IF,3 min周期。- R. p; W, m% ~# h& C8 G' S' n7 n, e

原理如下:
此策略是根据短期及中长期均线确认行情方向,然后当行情突破近期高低点时进行趋势性开仓。
5 m2 P, s! a2 s5 H$ I; [
出场停利用常用的三条均线作为出场条件,根据进场后的行情创新高跟新低的次数控制用哪条均线出场,好处是防止刚刚进场后激活短期均线,容易错失大的行情。



  1. input:x(30),y(120),m(20),n(15);
  2. var:ma1(close),ma2(close);

  3. ma1=Average(close,x);
  4. ma2=Average(close,y);

  5. condition1=close>ma1 and ma1>ma2;
  6. condition2=close<ma1 and ma1<ma2;
  7. condition3=high > highest(high,m)[1];
  8. condition4=low <lowest(low,n)[1];
  9. //以上定义变量跟参数,对进场条件进行定义

  10. if marketposition=0 and condition1 and condition3 then buy next bar at market;
  11. //判断进场条件

  12. //////////////////////
  13. input:f1(10),f2(20),f3(30),stp(11);
  14. var:av1(0),av2(0),av3(0),position(0),stH(0),Hct(0),stl(0),lct(0);
  15. av1 = average(close, f1);
  16. av2 = average(close, f2);
  17. av3 = average(close, f3);
  18. position = marketposition;
  19. //定义常用的三条移动平均线

  20. if position =1 and position[1] =0 then begin
  21. stH = high;
  22. Hct =0;
  23. end;
  24. //进场后对第一个bar高点赋值

  25. if position =1 and close > stH then begin
  26. stH = high;
  27. Hct = Hct[1] +1;
  28. end;
  29. //后面对创新高时进行累加计算

  30. if position =1 then begin
  31. if Hct <3 then sell("begin stop") next bar at entryprice - stp stop;
  32. if Hct >=3 and Hct <6 then sell("30stop") next bar at av3 stop;
  33. if Hct >=6 and Hct <9 then sell("20stop") next bar at av2 stop;
  34. if Hct >=9 then sell ("10stop") next bar at av1 stop;
  35. end;
  36. //当有持仓时,累加值作为激活某条均线的出场条件,有长期均线激活开始,这样可以防止进场后快速被洗出来。

  37. ////////////////////////
  38. if marketposition=0 and condition2 and condition4 then sellshort next bar at market;
  39. if position =-1 and position[1] =0 then begin
  40. stl = low;
  41. lct =0;
  42. end;
  43. if position =-1 and close < stl then begin
  44. stl = low;
  45. lct = lct[1] +1;
  46. end;
  47. if position =-1 then begin
  48. if lct <3 then buytocover("begin stop1") next bar at entryprice + stp stop;
  49. if lct >=3 and lct <6 then buytocover("30stop1") next bar at av3 stop;
  50. if lct >=6 and lct <9 then buytocover("20stop1") next bar at av2 stop;
  51. if lct >=9 then buytocover ("10stop1") next bar at av1 stop;
  52. end;
  53. //原理跟上面的多单进场出场条件判断一致,方向相反操作
复制代码

* z+ L6 Y* O1 \, e; l4 a









回复

使用道具 举报

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