金字塔趋势策略】-波浪策略

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

19

主题

36

回帖

201

积分

中级会员

积分
201
来源: 2020-3-12 19:39:03 显示全部楼层 |阅读模式
一、策略思想

     趋势交易是投资中非常常见的交易手法,其高收益吸引了众多的投资者通过观察,在一轮完整的趋势行情中,价格并不会一路上涨或下跌,正如波浪理论所解释的现象那样,在一波行情后会有一小段反向调整行情,之后再开始第二轮趋势行情。波浪策略就是通过寻找分析调整行情来确定下一轮趋势,从而进行操作获利。

二、交易逻辑
    以股指期货为例,具体交易步骤为
(1)买入开仓:
    (a)价格创20期新高;
    (b)创新高后3期内创2期新低;
    (c)创新低后3期内又创20期新高时买入开仓;
    (d)开仓后将止损价格设置为(b)步骤中2期新低价格;
    (e)当盈利达到2倍风险数额时,即2×开仓价格一止损价格|,平仓止盈。

(2)卖出开仓:
    (a)价格创20期新低;
    (b)创新低后3期内创2期新高;
    (c)创新高后3期内又创20期新低时卖出开仓;
    (d)开仓后将止损价格设置为(b)步骤中2期新高价格;
    (e)当盈利达到2倍风险数额时,即2×|开仓价格-止损价格|,平仓止盈。


三、金字塔源码
  1. //定义全局变量并初始化
  2. //nlow记录创20新高后3期内创2期新低时k线的最低值
  3. //mhigh记录创20期新低后3期内创2期新高时k线的最高值
  4. VARIABLE:nlow=0,mhigh=0;



  5. //定义参数
  6. Input:snum(1,1,100,1);



  7. //中间变量
  8. h20:=ref(hhv(h,20),1);    //20周期最高价
  9. l20:ref(llv(l,20),1);          //20周期最低价
  10. h2:=ref(hhv(h,2),1);       //2周期最高价
  11. l2:=ref(llv(l,2),1);           //2周期最低价



  12. //创20新高后3期内创2期新低,记录最低价
  13. con1:=BARSLAST(h>h20)<=3 and low<l2;
  14. if con1 then nlow:=low;


  15. //创20期新低后3期内创2期新高,记录最高价
  16. con2:=barslast(low<l20)<=3 and high>h2;
  17. if con2 then mhigh:=high;


  18. //交易条件

  19. //开多平多条件
  20. BuyCond:=barslast(con1)<=3 and high>h20;
  21. SellCond1:=low<=nlow;
  22. SellCond2:high-enterprice>2*abs(enterprice-nlow);


  23. //开空平空条件
  24. BuyshortCond:=barslast(con2)<=3 and l<l20;
  25. SellshortCond1:=high>=mhigh;
  26. SellshortCond2:enterprice-low>=2*abs(mhigh-enterprice);


  27. //下单模块

  28. if SellCond1 then 多损:Sell(holding>0,snum,market);
  29. if SellCond2 then 多盈:Sell(holding>0,snum,market);

  30. if SellshortCond1  then 空损:sellshort(holding<0,snum,market);
  31. if SellshortCond2  then 空盈:sellshort(holding<0,snum,market);

  32. //开空
  33. if BuyshortCond then buyshort(holding=0,snum,market);


  34. //开多
  35. if BuyCond then Buy(holding=0,snum,market);
复制代码


回复

使用道具 举报

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