Atr - exit trailing stop模块(公开课中atr移动止盈出场程式码)
- UID
- 2
- 积分
- 2738937
- 威望
- 1319465 布
- 龙e币
- 1419472 刀
- 注册时间
- 2009-12-3
- 最后登录
- 2024-5-23
|
Atr - exit trailing stop模块(公开课中atr移动止盈出场程式码)
程式码:- Input:atrlen(30),trailatrmult(3);
- var:lexit(0),sexit(0),atr1(0),top(0),bot(0);
- atr1 = atr(atrlen);
- if barssinceentry = 0 then begin //inital high and low
- top = high;
- bot = Low;
- end;
- if high > top then top = high; //find the highest point since entry
- if Low < bot then bot = low; // find then lowest point sine entry
- if marketposition = 1 then begin // manage long position
- lexit = top - trailatrmult*atr1;
- if barssinceentry=0 and Close < lexit then sell("Atr-nextdayout") all shares next bar at Open;
- if barssinceentry>0 then begin
- sell("atr-tail-stop") all shares next bar at lexit stop;
- value1 = tl_new(date[1],time,lexit[1],date,time,lexit);
- end;
- end;
- if marketposition = -1 then begin //manage short position
- sexit = bot + trailatrmult*atr1;
- if barssinceentry=0 and Close > sexit then sell("atr-nextdayout") all shares next bar at Open;
- if barssinceentry>0 then begin
- buytocover("atr-trail-stop") all shares next bar at sexit stop;
- value1 = tl_new(date[1],time,sexit[1],date,time,sexit);
- end;
- end;
复制代码 其中公式atr程式码:
本帖隐藏的内容需要回复才可以浏览
其中tr程式码:
本帖隐藏的内容需要回复才可以浏览
这个是我使用的原教旨atr的写法,在MC中原也是有atr的公式的,关键字是averagetruerange. |
论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
|
|
|
|
|
|
- UID
- 22603
- 积分
- 210
- 威望
- 105 布
- 龙e币
- 105 刀
- 注册时间
- 2022-8-18
- 最后登录
- 2023-12-11
|
2#
发表于 2023-10-18 14:55
| 只看该作者
哇,谢谢龙版 |
|
|
|
|
|
|
- UID
- 21723
- 积分
- 390
- 威望
- 195 布
- 龙e币
- 195 刀
- 注册时间
- 2021-4-15
- 最后登录
- 2024-4-11
|
3#
发表于 2023-10-21 15:22
| 只看该作者
|
|
|
|
|
|
- UID
- 22996
- 积分
- 4070
- 威望
- 2035 布
- 龙e币
- 2035 刀
- 注册时间
- 2023-7-21
- 最后登录
- 2024-5-21
|
4#
发表于 2023-11-5 21:10
| 只看该作者
|
|
|
|
|
|
- UID
- 23211
- 积分
- 572
- 威望
- 286 布
- 龙e币
- 286 刀
- 注册时间
- 2024-2-25
- 最后登录
- 2024-5-12
|
5#
发表于 2024-2-26 21:18
| 只看该作者
|
|
|
|
|
|