以文本方式查看主题

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

--  作者:2017gogogoo
--  发布时间:2017/8/22 15:08:06
--  信号闪烁

情况下面一段平仓语句,如果必须要用c,那么怎么才能使信号不闪烁呢?试了好几种方法,都没有达到效果,求版主帮忙!!!

 

 

//ATR止损
if   c<dzsATR and holding>0 then BEGIN
 sell(1,holding,marketr);
 dzsATR:=drawnull;
 doubleATR:=drawnull;
 threeATR:=drawnull;
 eckcON:=1;
end 


--  作者:2017gogogoo
--  发布时间:2017/8/22 15:08:51
--  
对了,运行在1分钟K线上。
--  作者:wenarm
--  发布时间:2017/8/22 15:09:41
--  

dzsATR这个是什么条件?天锤完整的代码。

[此贴子已经被作者于2017/8/22 15:10:00编辑过]

--  作者:2017gogogoo
--  发布时间:2017/8/22 15:10:57
--  

全部代码如下:

 

input:ss(2,1,999,1),t(0,0,400000,1),p(0,0,400000,1);
VARIABLE:dzsATR=drawnull,doubleATR=drawnull,threeATR=drawnull,cfT=0,CFP=0,eckcON=0;//eckcON为二次开仓开关。
ATR:= ref(MA(tr,20),1);
abb:=(time0-timetot0(dynainfo(207))<=20) or not(islastbar);
mck:=(h-l)/ma(tr,20);
3D:=if(ref(holding,1)>0,llv(ref(l,1),2),drawnull);
hh:if(cfT=0 and t<>0,t,drawnull),LINETHICK2,COLORRED;
hhh:if(cfP=0 and p<>0,p,drawnull),LINETHICK2,COLORMAGENTA;


///////////////////收盘和夜盘平仓模块//////////////////////////////////////////////////////////////////////////////
neipan:=STRNCMP(STKNAME,\'螺纹\',4)=0 or STRNCMP(STKNAME,\'矿石\',4)=0 or STRNCMP(STKNAME,\'轧卷\',4)=0 or
  STRNCMP(STKNAME,\'焦炭\',4)=0 or STRNCMP(STKNAME,\'焦煤\',4)=0 or STRNCMP(STKNAME,\'玻璃\',4)=0 or
  STRNCMP(STKNAME,\'动力\',4)=0 or STRNCMP(STKNAME,\'鸡蛋\',4)=0 or STRNCMP(STKNAME,\'硅铁\',4)=0 or
  STRNCMP(STKNAME,\'锰硅\',4)=0 or STRNCMP(STKNAME,\'橡胶\',4)=0 or STRNCMP(STKNAME,\'玉米\',4)=0 or
  STRNCMP(STKNAME,\'淀粉\',4)=0 ; //内盘品种
youse:=STRNCMP(STKNAME,\'沪铜\',4)=0 or STRNCMP(STKNAME,\'沪锌\',4)=0 or STRNCMP(STKNAME,\'沪铝\',4)=0 or
  STRNCMP(STKNAME,\'沪镍\',4)=0 or STRNCMP(STKNAME,\'沪锡\',4)=0 or STRNCMP(STKNAME,\'沪铅\',4)=0 ;
guijin:=STRNCMP(STKNAME,\'白银\',4)=0 or STRNCMP(STKNAME,\'黄金\',4)=0;
huanggongnongchan:=STRNCMP(STKNAME,\'沥青\',4)=0 or STRNCMP(STKNAME,\'豆一\',4)=0 or 
  STRNCMP(STKNAME,\'塑料\',4)=0 or STRNCMP(STKNAME,\'豆粕\',4)=0 or STRNCMP(STKNAME,\'棕榈\',4)=0 or
  STRNCMP(STKNAME,\'聚氯\',4)=0 or STRNCMP(STKNAME,\'豆油\',4)=0 or STRNCMP(STKNAME,\'豆粕\',4)=0 or
  STRNCMP(STKNAME,\'聚丙\',4)=0 or STRNCMP(STKNAME,\'棉花\',4)=0 or STRNCMP(STKNAME,\'新菜\',4)=0 or
  STRNCMP(STKNAME,\'白糖\',4)=0 or STRNCMP(STKNAME,\'P\',1)=0  or STRNCMP(STKNAME,\'甲醇\',4)=0 or
  STRNCMP(STKNAME,\'菜粕\',4)=0 ;

IFclose:=if(time=190000  or (time=050000 and youse) or (time=063000 and guijin) or
  (time=033000 and huanggongnongchan) or (time=030000 and STRNCMP(STKNAME,\'沥青\',4)=0),1,0 );

if IFclose and abb and dynainfo(54)<>c and holding>0 then begin
 sell(1,holding,marketr);
 dzsATR:=drawnull;
 doubleATR:=drawnull;
 threeATR:=drawnull;
end
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 


//开多

if  h>=hh and holding=0 and not(IFclose) then BEGIN 
 buy(1,ss,limitr,hh+mindiff*4),IGNORECHECKPRICE;
 dzsATR:=hh-ATR;
 doubleATR:=hh+ATR*2;
 threeATR:=hh+ATR*3;
 cfT:=1;
end


if h>=hhh then begin
 if  holding=0 and eckcON=1 and not(IFclose) then BEGIN 
  buy(1,ss,limitr,hhh+mindiff*4),IGNORECHECKPRICE;
  dzsATR:=hhh-ATR;
  doubleATR:=hhh+ATR*2;
  threeATR:=hhh+ATR*3;
 end  
 if h>hhh or (h=hhh and eckcON=1) then cfP:=1;
end


//破3根K线最低价平仓
if holding>0 and l<3D then BEGIN
   sell(1,holding,marketr);
 dzsATR:=drawnull;
 doubleATR:=drawnull;
 threeATR:=drawnull;
 eckcON:=1;
end
 
 
//ATR止损
if   c<dzsATR and holding>0 then BEGIN
 sell(1,holding,marketr);
 dzsATR:=drawnull;
 doubleATR:=drawnull;
 threeATR:=drawnull;
 eckcON:=1;
end  


if holding>0 then begin
 if h>doubleATR then dzsATR:=max(dzsATR,ENTERPRICE-mindiff*4);//突破2倍ATR后上移止损
 if h>threeATR  then dzsATR:=max(dzsATR,ENTERPRICE-mindiff*2);//突破3倍ATR后上移止损
end


//脉冲大K线平仓
ccl:=openint<ref(openint,1);
if ((time>=010100 and time<=010500 )or (time>=130100 and time<=130500)) and holding>0 and ccl and mck>5 and (h-c)>mindiff*2 then begin
 sell(1,holding,marketr);
 dzsATR:=drawnull;
 doubleATR:=drawnull;
 threeATR:=drawnull;
end

 

//日内全局变量归零处理
if time=CLOSETIME(0) then eckcON:=0;


止损线:max(dzsATR,3D),COLORGREEN;


//调试
2atrr:doubleATR;
3atr:threeatr;


--  作者:2017gogogoo
--  发布时间:2017/8/22 15:17:28
--  
运行在高频模式之下,按我的理解,触发了止损之后,dzsATR这个变量被赋予了空值,应该不存在闪烁的问题,但我实盘的时候确实有闪烁,不知道怎么回事?
[此贴子已经被作者于2017/8/22 15:17:53编辑过]

--  作者:FireScript
--  发布时间:2017/8/22 16:20:06
--  
感觉问题出在:dzsATR的赋值在几个地方都有,而这个赋值语句需要的条件可能有不确定性。你这里面变量相互关联的还挺多的。
--  作者:2017gogogoo
--  发布时间:2017/8/22 18:14:05
--  

问题应该不在dzsATR上。我加一个变量判断,这样可以避免闪烁吗, 是不是就可以把信号固定下来呢?

 

 

//ATR止损
cfstop:=0;//触发止损

if c<dzsATR then cfstop:=1;
if   cfstop and holding>0 then BEGIN
 sell(1,holding,marketr);
 dzsATR:=drawnull;
 doubleATR:=drawnull;
 threeATR:=drawnull;
 eckcON:=1;
end  

[此贴子已经被作者于2017/8/22 18:15:19编辑过]

--  作者:wenarm
--  发布时间:2017/8/23 8:58:49
--  

cfstop:=0;//触发止损

全局变量?

 

close本身就在不停的变动,信号不好固定。你上面的方式是如果是全局变量进行记录标记的话,那在什么时候初始化为0,并且初始化为0的条件会不会因为因子的变化而闪,

你这种互锁也不能从根本上处理闪烁的问题,只能从条件入手

 

 

drawnull;不要用这种赋值,鬼知道这个值会不会影响序列变量的计算。


 


--  作者:2017gogogoo
--  发布时间:2017/8/23 13:35:25
--  
以下是引用wenarm在2017/8/23 8:58:49的发言:

cfstop:=0;//触发止损

全局变量?

 

close本身就在不停的变动,信号不好固定。你上面的方式是如果是全局变量进行记录标记的话,那在什么时候初始化为0,并且初始化为0的条件会不会因为因子的变化而闪,

你这种互锁也不能从根本上处理闪烁的问题,只能从条件入手

 

 

drawnull;不要用这种赋值,鬼知道这个值会不会影响序列变量的计算。


 

1,我考虑用全局变量标记。2,关于drawnull函数,wenarm版主上次不是说可以这样赋值吗?而且从实盘情况来看,没有任何问题http://www.weistock.com/bbs/dispbbs.asp?BoardID=4&ID=156768&replyID=&skin=1


--  作者:2017gogogoo
--  发布时间:2017/8/23 15:15:45
--  

版主看看我这样处理能不能解决信号闪烁问题:

 

定义全局变量记录开仓以来的最低价,这样可不可行?

 

//ATR止损

variable:minC=0;

if holding>0 then minC:=(minC,c);
if   minC<dzsATR and holding>0 then BEGIN
 sell(1,holding,marketr);
 dzsATR:=drawnull;
 doubleATR:=drawnull;
 threeATR:=drawnull;
 eckcON:=1;
end