以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  自己做的持仓同步,请问为何没有开平仓动作  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=50881)

--  作者:stockwiner
--  发布时间:2013/4/10 9:28:19
--  自己做的持仓同步,请问为何没有开平仓动作
由于金字塔只能对单框架单策略进行持仓同步,所以我自己编了一段代码,用于图表交易的持仓同步,感觉应该可以实现这个功能,但在实际测试中,发现没有开平仓动作,特此请教一下。
图表交易,连续合约,代码如下:
currsec:=timetot0(dynainfo(207));
oldcc:Tholding2,noaxis,linethick0;//当前持仓
  newcc:holding,noaxis,linethick0;//理论应该的持仓
if mod(currsec,10)=0 and oldcc<>newcc then //持仓同步,每10秒一次
begin
  if sgn(oldcc)<>sgn(newcc) then  //新的持仓与原持仓方向相反,平仓原所有持仓
  begin
    sell(oldcc>0,100%,marketr);
    sellshort(oldcc<0,100%,marketr);
    buy(newcc>0,newcc,marketr);
    buyshort(newcc<0,-newcc,marketr);
    //buy(1,1,limitr,21000),IGNORECHECKPRICE;//在实际测试中,这个代码有开仓持单动作
  end
  else  //新的持仓与原持仓方向相同
  begin
   temp:=newcc-oldcc;
   buy(oldcc>0 and temp>0,temp,marketr);
   sell(oldcc>0 and temp<0,-temp,marketr);
   buyshort(oldcc<0 and temp<0,-temp,marketr);
   sellshort(oldcc<0 and temp>0,temp,marketr);
 end
end

--  作者:jinzhe
--  发布时间:2013/4/10 9:47:55
--  
没有找到对应的图表同步持仓模板,难度比较大,你这个用了动态时间和实际持仓,还不好进行调试
--  作者:RogarZ
--  发布时间:2013/4/10 9:48:10
--  

这个需要你用debugfile自己调试了。光一部分代码我们也帮不上的。

理论上是对的,只有执行了才知道。并且tholding2这些一直在变得,只有调试了才知道到底出了什么问题


--  作者:stockwiner
--  发布时间:2013/4/10 10:11:00
--  
 我用debugfile试了一下,     debugfile(\'d:\\tt.txt\',\'当前持仓\',oldcc);
结果显示为:
2013-04-10 10:05:30.836    当前持仓
2013-04-10 10:05:31.319    当前持仓

说明当前的oldcc变量没有数值,问题是:指标公式显示的变量是有数值的呀:
图片点击可在新窗口打开查看

--  作者:RogarZ
--  发布时间:2013/4/10 10:44:27
--  

http://www.weistock.com/bbs/dispbbs.asp?boardid=4&Id=49428

仔细看函数说明!!!

debugfile(\'d:\\tt.txt\',\'当前持仓%.0F\',oldcc);

请问红字部分去哪了?

别偷工减料,把东西给省略了

 


--  作者:stockwiner
--  发布时间:2013/4/10 10:49:28
--  
我加上了"0%f"
我现在怀疑是模拟交易系统的问题

我现在用buy(1,1,marketr)也没动作

--  作者:stockwiner
--  发布时间:2013/4/10 14:32:27
--  
2013-04-10 14:29:33.191    【图表】触发下单 SHELLSHORT 品种 IF00
2013-04-10 14:29:33.191    【图表】分品种下单调整后,系数1
2013-04-10 14:29:33.191    【图表】模型下单 9
2013-04-10 14:29:33.191    【图表】下单系数调整后 手数:9
2013-04-10 14:29:33.191    【图表】实际持仓 -19
2013-04-10 14:29:33.191    【图表】直接下单
2013-04-10 14:29:33.191    【图表】IF00 运行完毕
2013-04-10 14:29:33.191    【下单】IF04 价0.000000 量9 买卖0 类型1 开平1 账户805847 Formula 1
2013-04-10 14:29:33.206    当前尚有未处理完事件 - 6021

请问6021事件是什么?

--  作者:jinzhe
--  发布时间:2013/4/10 14:33:41
--  
模拟交易中,上一单交易没有收到成交回报,就会有报  未处理完事件
--  作者:王锋
--  发布时间:2013/4/10 15:29:05
--  

你应该在登录模拟交易后,弹出的通知,好好看看。

建议你使用仿真交易


--  作者:fly
--  发布时间:2013/4/12 11:00:30
--  

//用全局变量,实现次周期恢复持仓功能,供参考

 

buycond:=ref(count(c>o,2)=2,1);
sellcond:=ref(count(c<o,2)=2,1);

if holding>0 and sellcond and not(islastbar) then sell(1,1,marketr);
if holding<0 and buycond and not(islastbar) then sellshort(1,1,marketr);

if buycond and holding=0 and not(islastbar) then
 begin
 buy(1,1,marketr);
 end
 
if holding=0 and sellcond and not(islastbar) then buyshort(1,1,marketr);

 
if islastbar and tholding2<>holding then
 begin
  if barpos=EXTGBDATA(\'kai\')+1 then//开仓信号消失,平仓恢复仓
  begin
  sell(tholding2>0,1,marketr);
  sellshort(tholding2<0,1,marketr);
  EXTGBDATASET( \'kai\',0);
  end
  
  if barpos=EXTGBDATA(\'ping\')+1 then//平仓信号消失,开仓恢复仓
  begin
  buy(holding>0,1,marketr);
  buyshort(holding<0,1,marketr);
  EXTGBDATASET( \'ping\',0);
  end    
 end

if holding>0 and sellcond and islastbar then
begin
sell(1,1,marketr);
EXTGBDATASET( \'ping\',BARPOS);
end

if holding<0 and buycond and islastbar then
begin
sellshort(1,1,marketr);
EXTGBDATASET( \'ping\',BARPOS);
end


//全局变量BAR,信号消失一根K线上也只开一次仓
if ISLASTBAR AND buycond and barpos>EXTGBDATA(\'kai\') and holding=0 then
 begin
 buy(1,1,marketr);
 EXTGBDATASET( \'kai\',BARPOS);
 end

if ISLASTBAR AND sellcond and barpos>EXTGBDATA(\'kai\') and holding=0 then
 begin
 buyshort(1,1,marketr);
 EXTGBDATASET( \'kai\',BARPOS);
 end