开拓者期货期权程序化系统交易论坛

标题: 如何编写加仓命令! [打印本页]

作者: dengwenle    时间: 2007-9-14 01:24:43     标题: 如何编写加仓命令!

如果 condtion 条件继续成立 怎么编写加仓命令呢 ?

Numeric extryLots; // 加仓数量
、、、、、、、
//加仓
if (BarStatus == 2 and MarketPosition == -1 )       
   {extryLots=A_FreeMargin /(Q_AskPrice*ContractUnit*MarginRatio);
   extryLots  = IntPart(extryLots );
   if(condtion and Time<0.144500 )                       
     SellShort( extryLots  ,Close,True);
   }
Else If(BarStatus <> 2 and MarketPosition == -1 )       
  {extryLots=CurrentCapital/(Close*ContractUnit*MarginRatio);
    extryLots  = IntPart(extryLots ); // 取整
        if(condtion and Time<0.144500 )                       
      SellShort( extryLots  ,Close,True);
   
    }
在 condtion  第一次成立后 ,开仓,  在部分仓位止赢后, 还剩下部分仓位 !这个时候 condtion  条件又成立了!
在这样的情况如何加仓!
我写的是加空的 代码 好象不行!

[ 本帖最后由 dengwenle 于 2007-9-14 01:26 编辑 ]
作者: nopain    时间: 2007-9-14 09:27:52

看起来代码没有问题,您用FileAppend函数调试一下,确认是否执行到加仓的代码
代码如下:

  1. if (BarStatus == 2 and MarketPosition == -1)
  2. {
  3.         extryLots=A_FreeMargin /(Q_AskPrice*ContractUnit*MarginRatio);
  4.         extryLots  = IntPart(extryLots );
  5.         if(condtion and Time<0.144500 )
  6.         {
  7.                FileAppend("C:\\Formula.log","Date_lastbar="+Text(Date)+",Time_lastbar="+Text(100*Time)+",extryLots="+Text(extryLots));
  8.                SellShort( extryLots  ,Close,True);
  9.         }
  10. }Else If(BarStatus <> 2 and MarketPosition == -1 )
  11. {
  12.         extryLots=CurrentCapital/(Close*ContractUnit*MarginRatio);
  13.         extryLots  = IntPart(extryLots ); // 取整
  14.         if(condtion and Time<0.144500 )                       
  15.         {
  16.                FileAppend("C:\\Formula.log","Date="+Text(Date)+",Time="+Text(100*Time)+",extryLots="+Text(extryLots));
  17.                SellShort( extryLots  ,Close,True);
  18.         }
  19. }
复制代码

[ 本帖最后由 nopain 于 2007-9-14 12:07 编辑 ]
作者: dengwenle    时间: 2007-9-14 11:40:07

测试的结果 如下
Formula文件的内容::

Time=0.09,extryLots=215
Time=0.11,extryLots=217
Time=0.14,extryLots=217
Time=0.14,extryLots=218
Time=0.14,extryLots=222
Time=0.13,extryLots=222




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2