Board logo

标题: 止损止盈(二) [打印本页]

作者: 龙听    时间: 2017-12-21 22:34     标题: 止损止盈(二)

原文合作出处:Ray's Blog

这次要来介绍的是一种止盈的方法, 以函数的方式呈现, 如此方便套用在任何策略中,要注意的是,此方法只有止盈,止损需要额外添加喔

方式如下:




利用highest(high,barssinceentry)-entryprice>10 条件成立
挂单在highest(high,barssinceentry)-(0.5)*(highest(high,barssinceentry)-entryprice)
这样的写法做移动停利取代Setpercenttrailing / Setdollartrailing
写法还蛮简单的,原本是个别拆开写在策略中.
为了方便大家使用,所以改成函数的方式.
可以自己测试看看..

函数:
NetTrailling(N,ratio)

说明:
N->进场后获利N点后,启动移动停利.
ratio ->拉回多少出场,分为拉回点数及百分比
从最高获利拉回50%,就填入0.5 ,
从最高获利拉回20点出场就写20.

ex:
买入后获利大于20点,拉回10点出场:NetTrailling(20,10)
if date<>date[1] and close>close[1] then buy next bar at market;
if marketposition>0 then sell next bar at NetTrailling(20,10) stop;
(放空相同NetTrailling(20,10)-> buytocover next bar at NetTrailling(20,10) stop)



作者: 龙听    时间: 2017-12-21 22:35

NetTrailling 函数源码:
  1. vars:btrailling(0),STrailling(0),s(0);
  2. if r<=1 then s=0 else s=1;
  3. switch(s)
  4. begin
  5. case 0:
  6. if (highest(high,barssinceentry)-entryprice)>N then
  7. btrailling= highest(high,barssinceentry)-r*(highest(high,barssinceentry)-entryprice)
  8. else btrailling=0;
  9. if (entryprice-lowest(low,barssinceentry))>N then
  10. STrailling= lowest(low,barssinceentry)+r*(entryprice-lowest(low,barssinceentry))
  11. else STrailling=99999;
  12. case 1:
  13. if (highest(high,barssinceentry)-entryprice)>N then
  14. btrailling= highest(high,barssinceentry)-r point
  15. else btrailling=0;
  16. if (entryprice-lowest(low,barssinceentry))>N then
  17. STrailling= lowest(low,barssinceentry)+r point
  18. else STrailling=99999;
  19. end;
  20. if marketposition>0 then NetTrailling=btrailling;
  21. if marketposition<0 then NetTrailling=strailling;
复制代码





欢迎光临 龙听期货论坛 (http://www.qhlt.cn/) Powered by Discuz! 7.2