龙听期货论坛's Archiver

C
+
+


 微信: QQ:

龙听 发表于 2017-12-21 22:34

止损止盈(二)

原文合作出处:Ray's Blog

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

方式如下:

[img]http://p.qhlt.cn/filestores/2017/12/21/72898418012561d7a1e3212c41b15187.jpg[/img]


利用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)


[img]http://p.qhlt.cn/filestores/2017/12/21/f5e43024336a1c9614e1f492ab8d60cd.jpg[/img]

龙听 发表于 2017-12-21 22:35

NetTrailling 函数源码:[code]
vars:btrailling(0),STrailling(0),s(0);
if r<=1 then s=0 else s=1;
switch(s)
begin
case 0:
if (highest(high,barssinceentry)-entryprice)>N 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<0 then NetTrailling=strailling;
[/code]

新乙手 发表于 2024-6-3 11:19

谢谢分享

页: [1]
渠道·推广(20年运营值得信赖!)▼:温馨提示:期货论坛稳定、流畅的访问体验有赖于赞助商的广告支持,赞助商业务内容非本站官方业务,期货、证券及外汇投资均有亏损的风险,访问赞助商广告即代表您已了解其中的风险。欢迎意向赞助商联系客服或管理员咨询相关事宜。
                     
❤️2025年通过期货论坛开户享受如下优惠政策:政策一:手续费最低交易所+1分起,政策二:日内炒单及大资金享更高比率返还,政策三:保证金可申请交易所标准+0,政策四:开户即享有论坛Prime会员资格(价值199元/年),开户咨询管理员或右侧客服! 😋欧美期货杂志购买、下载与中文翻译:/thread-10603-1-1.html |TB/MC开户优惠政策:/thread-5986-1-1.html2025年最新交易所手续费表:/thread-7537-1-1.htmlSC2.png2025年最新中文翻译:/thread-160355-1-1.html;
欧美期货程序化期刊中文翻译目录: 【1982/83.01-12期】 【1984.01-12期】 【1985.01-12期】 【1986.01-12期】 【1987.01-12期】 【1988.01-12期】 【1989.01-12期】 【1990.01-12期】 【1991.01-12期】 【1992.01-12期】 【1993.01-12期】 【1994.01-12期】 【1995.01-12期】 【1996.01-12期】 【1997.01-12期】 【1998.01-12期】 【1999.01-12期】 【2000.01-12期】 【2001.01-12期】 【2002.01-12期】 【2003.01-12期】 【2004.01-12期】 【2005.01-12期】 【2006.01-12期】 【2007.01-12期】 【2008.01-12期】 【2009.01-12期】 【2010.01-12期】 【2011.01-12期】 【2012.01-12期】 【2013.01-12期】 【2014.01-12期】正在更新中...... 【2015.01-12期】待补 【2016.01-12期】待补 【2017.01-12期】正在更新中...... 【2018.01-12期】 【2019.01-12期】 【2020.01-12期】 【2021.01-12期】 【2022.01-12期】 【2023.01-12期】 【2024.01-12期】 【2025.01-12期】正在更新中......