以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  加入交易次数限制后结果异常  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=67917)

--  作者:cssfortune
--  发布时间:2014/7/28 12:22:59
--  加入交易次数限制后结果异常

早盘突破系统,1分钟上测试2年,

刚开始写完交易次数是1700多;后来添加了一个每天只能交易一手的条件,结果交易次数只有3次了!

添加了交易次数限制的代码如下,是我写的逻辑出错了吗?

 

input:T(30,5,60,5),
SS(1,1,10,1),
U(1,1,10,1),
D(1,1,10,1),
CS(1,1,5,1);//交易次数限制
VARIABLE:NUM=0;//统计开仓动作

 

n:=barslast(date<>ref(date,1))+1;//开盘以来的K线数量
hh:=hhv(high,n);//开盘以来的高价
H30:=valuewhen(time>=opentime(1) and time<=opentime(1)+T*100,hh);//30分钟内的高价
ll:=llv(low,n);//开盘以来的低价
L30:=valuewhen(time>=opentime(1) and time<=opentime(1)+T*100,ll);//30分钟内的低价
上轨:H30+U*MINDIFF,linethick2;
下轨:L30-D*MINDIFF,linethick2;
buycond:=cross(high,上轨);//做多条件
buyshortcond:=cross(下轨,low);//做空条件
buyprice:=max(open,上轨)+1*mindiff;//开多价格
buyshortprice:=min(open,下轨)-1*mindiff;//开空价格

 

stopbuy:max(valuewhen(n=1,open),ref(high,1)*(1-0.5/100)),linedot;//多头止损价位

stopshort:min(valuewhen(n=1,open),ref(low,1)*(1-0.5/100)),linedot;//空头止损价位
sellcond:=cross(stopbuy,low);//平多条件
sellshortcond:=cross(high,stopshort);//平空条件
sellprice:=min(open,stopbuy)-1*mindiff;//平多价格
sellshortprice:=max(open,stopshort)+1*mindiff;//平空价格


entertime:=time>opentime(1)+T*100 and time<closetime(0)-10*100;//入场交易时间
exittime:=time>=closetime(0)-10*100;//平仓离场时间

 

if entertime and holding=0 and num<CS then  {开仓入场}
begin 
 if buycond then
    BEGIN
    buy(1,ss,limitr,buyprice);
    NUM:=NUM+1;
    END
 else if buyshortcond then
    BEGIN
    buyshort(1,ss,limitr,buyshortprice);
    NUM:=NUM+1;
    END
end

 

if enterbars>1 and holding<>0 then {止损离场}
begin
 if holding>0 and sellcond then
    sell(1,ss,limitr,sellprice);
 else if holding<0 and sellshortcond then
    sellshort(1,ss,limitr,sellshortprice);
end

 

if exittime and holding<>0 then  {收盘平仓}
begin
  sell(holding>0,ss,limitr,open-1*mindiff);
  sellshort(holding<0,ss,limitr,open+1*mindiff);
  NUM:=0;
end

 

持仓:holding,linethick0;
净利润:netprofit,linethick0;
资产:asset,linethick0;
资金:cash(0),linethick0;


 
 

 

 

 

 

 

 

 

 


--  作者:cssfortune
--  发布时间:2014/7/28 12:24:43
--  
并且检查了一下图表,本来当天是数据是满足交易条件的,却没有显示也没有执行交易信号。
--  作者:jinzhe
--  发布时间:2014/7/28 13:22:14
--  

if exittime and holding<>0 then  {收盘平仓}
begin
  sell(holding>0,ss,limitr,open-1*mindiff);
  sellshort(holding<0,ss,limitr,open+1*mindiff);
  NUM:=0;
end

 

改成

 

if exittime and holding<>0 then  {收盘平仓}
begin
  sell(holding>0,ss,limitr,open-1*mindiff);
  sellshort(holding<0,ss,limitr,open+1*mindiff);
end

if exittime then   NUM:=0;


--  作者:cssfortune
--  发布时间:2014/7/28 13:35:51
--  

试了一下,的确纠正过来了图片点击可在新窗口打开查看谢谢、、