以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  atr指标止损  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=94604)

--  作者:tt782722334
--  发布时间:2016/3/10 21:10:28
--  atr指标止损
老师,我想用这个指标作为高低价突破入场,以atr指标作为离场,要怎么编写,下面的公式做参考,


variable: xstop=0;   

 tr:=max(high-low,max(abs(high-ref(close,1)),abs(low-ref(close,1)))); 
 atr:=sma(tr,20,1);   
    
 if high>=hhv(high,20) then   xstop:=llv(low,10); {20日新高,建立多头停损价格起点——最近10日低点}  
else if low>xstop then   xstop:=xstop+0.05*atr; {多头延续,每天跟踪停损价格上移ATR的5%}  
else if low<=llv(low,20) then   xstop:=hhv(high,10);{20日新低,建立空头停损价格起点——最近10日高点}  
else if high<xstop then   xstop:=xstop - 0.05*atr;{空头延续,每天跟踪停损价格下移ATR的5%}  
  StopPrice: xstop;{显示停损价格}

--  作者:wenarm
--  发布时间:2016/3/11 8:54:16
--  

正在处理,请耐心等待


--  作者:wenarm
--  发布时间:2016/3/11 10:11:20
--  

你上面提供的代码。逻辑是不是有问题?你描述下你的需求。

if high>=hhv(high,20) //  不成立时xstop=0。

else if low>xstop //这个位置肯定成立了。

--  作者:tt782722334
--  发布时间:2016/3/11 12:07:54
--  
是要在开仓后成立条件


--  作者:wenarm
--  发布时间:2016/3/11 12:36:05
--  
不明白你的意图。你自己整理下你的需求,要求怎么进行量化处理。需要你提供量化的思路