Board logo

标题: Atr - exit trailing stop模块(公开课中atr移动止盈出场程式码) [打印本页]

作者: 龙听    时间: 2023-10-18 06:43     标题: Atr - exit trailing stop模块(公开课中atr移动止盈出场程式码)

程式码:
  1. Input:atrlen(30),trailatrmult(3);
  2. var:lexit(0),sexit(0),atr1(0),top(0),bot(0);

  3. atr1 = atr(atrlen);

  4. if barssinceentry = 0 then begin //inital high and low
  5. top = high;
  6. bot = Low;
  7. end;

  8. if high > top then top = high; //find the highest point since entry
  9. if Low < bot then bot = low;  // find then lowest point sine entry

  10. if marketposition = 1 then begin // manage long position
  11. lexit = top - trailatrmult*atr1;
  12. if barssinceentry=0 and Close < lexit then sell("Atr-nextdayout") all shares next bar at Open;
  13. if barssinceentry>0 then begin
  14. sell("atr-tail-stop") all shares next bar at lexit stop;
  15. value1 = tl_new(date[1],time,lexit[1],date,time,lexit);
  16. end;
  17. end;

  18. if marketposition = -1 then begin //manage short position
  19. sexit = bot + trailatrmult*atr1;
  20. if barssinceentry=0 and Close > sexit then sell("atr-nextdayout") all shares next bar at Open;
  21. if barssinceentry>0 then begin
  22. buytocover("atr-trail-stop") all shares next bar at sexit stop;
  23. value1 = tl_new(date[1],time,sexit[1],date,time,sexit);
  24. end;
  25. end;
复制代码
其中公式atr程式码:

本帖隐藏的内容需要回复才可以浏览


其中tr程式码:

本帖隐藏的内容需要回复才可以浏览


这个是我使用的原教旨atr的写法,在MC中原也是有atr的公式的,关键字是averagetruerange.
作者: 斗战胜    时间: 2023-10-18 14:55

哇,谢谢龙版
作者: 加菲猫    时间: 2023-10-21 15:22

看看
作者: 龙听小虎    时间: 2023-11-5 21:10


作者: 小龍    时间: 2024-2-26 21:18

感恩




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