以文本方式查看主题

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

--  作者:tanyongde
--  发布时间:2016/12/1 16:22:04
--  止损
止损不知道那里写错,经常在编写模块出现开仓本k线就止损?怎么避免这种现象?
图片点击可在新窗口打开查看此主题相关图片如下:qq截图20161201161309.png
图片点击可在新窗口打开查看


//建立多头的进场条件

   if holding<0 and  long then begin
   
    sellshort(1,p,marketr);

    buy(1,p,marketr);
   
  end
 
 //建立空头的进场条件

   if holding>0 and short then begin

    sell(1,p,marketr);
   
    buyshort(1,p,marketr);
  
 end

if holding>0 and l<=max(enterprice-zsx,dstop1)  and enterbars1>0 then sell(1,p,market),ignorecheckprice;

if holding<0 and h>=min(enterprice+zsx,kstop1)  and enterbars1>0 then sellshort(1,p,market),ignorecheckprice;

if holding=0 and long and ref(c,1)>ref(4,1) then buy(1,p,marketr);

if holding=0 and short and ref(c,1)<ref(4,1) then buyshort(1,p,marketr);

if not(islastbar) or workmode<>1 then exit;
tm:=30;//撤单时间
ac:=\'614251\';//下单账户
wt:=tremainqty(0,ac,stklabel);
buyhold:=tbuyholdingex(ac,stklabel,1);
sellhold:=tsellholdingex(ac,stklabel,1);
if wt>0.5 and tsubmit(0)>tm then tcancelex(1,0,ac,stklabel);//如果用软件自带的撤单功能,这句删除。
if wt<0.5 then begin
 kc1:=max(cc,0)-buyhold;
 kc2:=abs(min(cc,0))-sellhold;
 if kc1<-0.5 then tsell(1,abs(kc1),mkt,0,0,ac),allowrepeat;
 if kc2<-0.5 then tsellshort(1,abs(kc2),mkt,0,0,ac),allowrepeat;
 if sellhold<0.5 and kc1>0.5 then tbuy(1,kc1,mkt,0,0,ac),allowrepeat;
 if buyhold<0.5  and kc2>0.5 then tbuyshort(1,kc2,mkt,0,0,ac),allowrepeat;
end


--  作者:jinzhe
--  发布时间:2016/12/1 16:33:42
--  
enterbars1指的是什么?
--  作者:tanyongde
--  发布时间:2016/12/1 17:50:21
--  
enterbars1:=enterbars+1;开仓历时
--  作者:tanyongde
--  发布时间:2016/12/2 8:13:49
--  
  把holding改成CC代替就解决,不知道是什么原因?
--  作者:jinzhe
--  发布时间:2016/12/2 9:07:17
--  

enterbars1>0改成enterbars>0

不然这个条件在开仓后恒成立,那么就会同根k线开仓


--  作者:tanyongde
--  发布时间:2016/12/2 9:11:30
--  
谢谢!!