以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  连续亏损三次则不再开仓。  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=80740)

--  作者:qq代人发帖
--  发布时间:2015/7/10 14:48:07
--  连续亏损三次则不再开仓。

连续亏损三次则不再开仓。
怎么写


--  作者:qq代人发帖
--  发布时间:2015/7/10 14:50:37
--  

限制一天交易次数

如何使用全局变量,来限定一天只交易3

  

variablenum=0;// 全局变量,来控制当天交易次数

cs:=3;//限定一天最多交易3次


ma5:=ma(5,close);

ma20:=ma(20,close);


con1:=cross(ma5,ma20);

con2:=cross(ma20,ma5);


if cond2 and holding>0 then sell(1,1,market);


if cond1 and holding=0 and num<3  then 

  begin

  buy(1,1,market);

  num:=num+1;

  end

if time=closetime(0) then num:=0;// 商品期货,收盘的同时,num赋值为0

//收盘num不赋值为0,第二天就不再开仓了

参考这个


--  作者:jinzhe
--  发布时间:2015/7/10 14:50:55
--  

这个需要把所有的平仓语句都要做下修改,修改范例如下

variable:n=0;//这个写在策略最开头,只写一次

 

//所有的平仓语句都做如下的修改

if 平空条件 and holding<0  then begin

   sellshort(1,0,market);

   if numprofit(1)>0 then n:=0;

   if numprofit(1)<0  then n:=n+1;

end

 

if 平多条件 and holding>0  then begin

   sell(1,0,market);

   if numprofit(1)>0 then n:=0;

   if numprofit(1)<0  then n:=n+1;

end

 

 

然后在所有开仓条件里面加入一个条件: n<3


--  作者:hesamfeng
--  发布时间:2015/7/10 15:41:48
--  
还是不能生效, 能不能帮我看看源代码? 怎么联系你?
--  作者:hesamfeng
--  发布时间:2015/7/10 15:42:23
--  
还是不能生效, 能不能帮我看看源代码? 怎么联系你?

--  作者:jinzhe
--  发布时间:2015/7/10 15:42:39
--  
发论坛邮件
--  作者:hesamfeng
--  发布时间:2015/7/10 15:48:53
--  回复:(jinzhe)发论坛邮件
{
INPUT:检索周期(830,100,1000,10);
INPUT:宽高比(7.5,1.5,10,0.5);
INPUT:宽比(65,20,80,5);
INPUT:高比(10,10,40,4);
}

variable:连续多损次数:=0;
variable:连续空损次数:=0;


IF主力:=CALLSTOCK(\'IF00\',VTCLOSE,12,0),COLORRED;
SH300:=CALLSTOCK(\'SH300\',VTCLOSE,12,0),COLORCYAN;
远高:HHV(H,检索周期);
远低:llv(l,检索周期);
上距离:=HHV(H,检索周期)-C,NODRAW;
下距离:=C-llv(l,检索周期),NODRAW;
高:远高-远低,NODRAW;
宽:abs(LLVBARS(L,检索周期)-HHVBARS(h,检索周期))*5/60,NODRAW;  //  时间分钟
高宽比:高/宽,NODRAW;
makgb:=ma(高宽比,300);



开多条件:=高>40 and LLVBARS(L,检索周期)*5/60<宽/宽比  AND 下距离>高/高比 and 高宽比>=宽高比 {and SH300<ref(SH300,1)} AND TIME>95000 and 连续多损次数<3 and HOLDING=0;
开空条件:=高>40 and HHVBARS(h,检索周期)*5/60<宽/宽比  and 上距离>高/高比 and 高宽比>=宽高比 {and SH300>ref(SH300,1)} AND TIME>95000 and 连续空损次数<3 and HOLDING=0;

平多条件:=c=远高;
平空条件:=c=远低;


//连续亏损三次不再开仓
//所有的平仓语句都做如下的修改
if 平空条件 and holding<0  then begin
   sellshort(1,0,market);
   if numprofit(1)>0 then 连续空损次数:=0;
   if numprofit(1)<0  then 
   BEGIN
   连续空损次数:=连续空损次数+1;
   end
end
 
if 平多条件 and holding>0  then begin
   sell(1,0,market);
   if numprofit(1)>0 then 连续多损次数:=0;
   if numprofit(1)<0  then 
   begin
   连续多损次数:=连续多损次数+1;
   end
end



//交易

开空:BUYSHORT(开空条件,1,MARKETR);
空盈:SELLSHORT(平空条件,0,MARKET);

开多:BUY(开多条件,1,MARKETR);
多盈:SELL(平多条件,0,MARKET);


//止损
if c>ref(远高,1) then
空损:SELLSHORT(1,0,MARKETR);

if c<ref(远低,1) THEN
多损: SELL(1,0,MARKETR);





当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;

--  作者:jinzhe
--  发布时间:2015/7/10 15:54:53
--  


INPUT:检索周期(50,50,1000,10);
INPUT:宽高比(7.5,1.5,10,0.5);
INPUT:宽比(65,20,80,5);
INPUT:高比(10,10,40,4);

 

variable:连续多损次数=0;
variable:连续空损次数=0;

 


IF主力:=CALLSTOCK(\'IF00\',VTCLOSE,12,0),COLORRED;
SH300:=CALLSTOCK(\'SH300\',VTCLOSE,12,0),COLORCYAN;
远高:HHV(H,检索周期);
远低:llv(l,检索周期);
上距离:=HHV(H,检索周期)-C,NODRAW;
下距离:=C-llv(l,检索周期),NODRAW;
高:远高-远低,NODRAW;
宽:abs(LLVBARS(L,检索周期)-HHVBARS(h,检索周期))*5/60,NODRAW;  //  时间分钟
高宽比:高/宽,NODRAW;
makgb:=ma(高宽比,300);

 

 


开多条件:=高>40 and LLVBARS(L,检索周期)*5/60<宽/宽比  AND 下距离>高/高比 and 高宽比>=宽高比 {and SH300<ref(SH300,1)} AND TIME>95000 and 连续多损次数<3 and HOLDING=0;
开空条件:=高>40 and HHVBARS(h,检索周期)*5/60<宽/宽比  and 上距离>高/高比 and 高宽比>=宽高比 {and SH300>ref(SH300,1)} AND TIME>95000 and 连续空损次数<3 and HOLDING=0;


平多条件:=c=远高;
平空条件:=c=远低;

 


//连续亏损三次不再开仓
//所有的平仓语句都做如下的修改
if 平空条件 and holding<0  then begin
   sellshort(1,0,market);
   if numprofit(1)>0 then 连续空损次数:=0;
   if numprofit(1)<0  then
   BEGIN
   连续空损次数:=连续空损次数+1;
   end
end
 
if 平多条件 and holding>0  then begin
   sell(1,0,market);
   if numprofit(1)>0 then 连续多损次数:=0;
   if numprofit(1)<0  then
   begin
   连续多损次数:=连续多损次数+1;
   end
end

 

 


//交易


开空:BUYSHORT(开空条件 and 连续空损次数<3,1,MARKETR);


开多:BUY(开多条件 and 连续多损次数<3,1,MARKETR);

 

 

//止损
if c>ref(远高,1) and holding<0 then begin
 SELLSHORT(1,0,MARKETR);
    if numprofit(1)>0 then 连续空损次数:=0;
   if numprofit(1)<0  then BEGIN
      连续空损次数:=连续空损次数+1;
   end
end


if c<ref(远低,1) and holding>0 THEN begin
 SELL(1,0,MARKETR);
 if numprofit(1)>0 then 连续多损次数:=0;
   if numprofit(1)<0  then
   begin
   连续多损次数:=连续多损次数+1;
   end
end

 

 

 

 

 

当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;

 


--  作者:hesamfeng
--  发布时间:2015/7/10 15:57:57
--  回复:(jinzhe)INPUT:检索周期(50,50,1000,10);...
请问改了哪里?
--  作者:jinzhe
--  发布时间:2015/7/10 16:02:04
--  
删了多余的平仓,在止损上加了全局变量计算