止损止盈(二)

原文合作出处: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 datedate[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)

宽客网,量化投资,宽客俱乐部

NetTrailling 函数源码:

vars:btrailling(0),STrailling(0),s(0);

if rN then

btrailling= highest(high,barssinceentry)-r*(highest(high,barssinceentry)-entryprice)

else btrailling=0;

if (entryprice-lowest(low,barssinceentry))>N then

STrailling= lowest(low,barssinceentry)+r*(entryprice-lowest(low,barssinceentry))

else STrailling=99999;

case 1:

if (highest(high,barssinceentry)-entryprice)>N then

btrailling= highest(high,barssinceentry)-r point

else btrailling=0;

if (entryprice-lowest(low,barssinceentry))>N then

STrailling= lowest(low,barssinceentry)+r point

else STrailling=99999;

end;

if marketposition>0 then NetTrailling=btrailling;

if marketposition<0then NetTrailling=strailling;NetTrailling.pla
程序化交易, MultiCharts

原文发布于宽客论坛,点击阅读原文



                                                    风险提示及免责条款

市场有风险,投资需谨慎。本文不构成个人投资建议,也未考虑到个别用户特殊的投资目标、财务状况或需要。用户应考虑本文中的任何意见、观点或结论是否符合其特定状况。据此投资,责任自负。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部