分析家公式网,提供指标公式,股票软件 用户登录  |  用户 注册

软件名称:[B]开拓者 TB 强悍的全局变量功能 及 源码范例 想成为开拓者高手必看[/B]
软件类型:国产软件
运行环境:Win2000/WinXP/Win2003/WinVista
软件语言:简体中文
授权方式:共享软件
软件大小:0 Bytes
官方主页:Home Page
更新时间:2013-03-18 02:42:14
软件简介:

   



  • 全自动的程序化交易必须解决以下三大难题:

    ⒈既要保证交易信号的及时性,又要做到信号不能反复;

    ⒉记录每一次系统开、平仓的价咯,以及账户的持仓变动,以便进行加减头寸及资金管理的安排;

    ⒊在同一根K线上进行交易控制,实现跨周期数据引用,以便精确实现短线交易时机的把握。

    通过三天的学习,依托交易开拓者软件全局变量的强大功能,我终于攻克了上述三大难关。

    除了普通变量外,交易开拓者软件提供了三种特殊变量,它们分别是:

    ⒈序列变量:可以进行数据的回溯,从而实现条件、循环语句的应用;它的运行特点是每一根BAR依次执行,这不同于坊间文华等其它交易软件评台的一次性运算。而且,它的全部函数均提供了算法,不同于黑箱的做法,有利于校对和修改。

    ⒉引用型变量:可以通过用户函数的形式,进行一劳永逸式的编写,避免程序的冗余。

    ⒊全局变量:用于中间计算过程的记录和存取,可以实现同一根BAR上的仓位管理与开平仓价咯记录。

    假设我们需要记录当前BAR的动态仓位状态,使用普通变量、序列变量都是无法完成这项任务的,必须使用全局变量来实施控制,并配合A_SENDORDER函数来发出买卖指令。比如,我们当条件满足时,分别记录买卖仓位的动态变化后,采用SET GLOBALVAR(0,1),记录当前的仓位为1手多单,然后可以不断改写第一个全局变量的值,在需要读取操作的时候,我们采用cw=getglobvar(0)的方式来实时地取回。使用全局变量时一定要进行初始化的设置,这样在系统断线后,只要不关闭相关图表,重连后的数据依然可以保持正确。切记不可简单使用BARSTATS的状态来确认全局变量,

    以下的这个例子较好地表述了套利系统中全局变量的应用。

    Params
    Bool  bInitStatus(False);  // 初始化标志,修改初始仓位时需设置为True
    Numeric EveryLots(1);    // 每次交易数量手数程序化交易
    Numeric LongEntryPrice(-100000); // 开多仓的触发价咯
    Numeric LongExitPrice(100000);  // 平多仓的触发价咯
    Numeric ShortEntryPrice(100000); // 开空仓的触发价咯
    Numeric ShortExitPrice(-100000); // 平空仓的触发价咯
    Numeric LongStartLots(0);    // 多仓的初始仓位(手数),必须是EveryLots的倍数
    Numeric LongEndLots(0);     // 多仓的最大仓位(手数),必须是EveryLots的倍数
    Numeric ShortStartLots(0);    // 空仓的初始仓位(手数),必须是EveryLots的倍数
    Numeric ShortEndLots(0);     // 空仓的最大仓位(手数),必须是EveryLots的倍数
    Numeric OffsetPoint(2);   // 委托价咯的偏移值(点数)
    Vars  
    Numeric SpreadUpper;
    Numeric SpreadLower;
    Numeric longPosition;
    Numeric shortPosition;
    Bool bLongEntryCon;
    Bool bShortEntryCon;
    Bool bLongExitCon;
    Bool bShortExitCon;
    Bool bTimeCon;
    Numeric Data0Lots(1);
    Numeric Data1Lots(2);
    Begin
    longPosition = GetGlobalVar(0);
    shortPosition = GetGlobalVar(1);
    If (BarStatus == 0)
    {
      If(longPosition == InvalidNumeric || bInitStatus)
      {
       longPosition = LongStartLots;
       SetGlobalVar(0,longPosition);
      }
      If(shortPosition == InvalidNumeric || bInitStatus)
      {
       shortPosition = ShortStartLots;
       SetGlobalVar(1,shortPosition);
      }
    }Else If(BarStatus == 2 && A_AccountID!="")
    {
      If(EveryLots < 1) Return;
      If(Data0.Q_AskPrice <= 0 || Data0.Q_BidPrice <= 0 || Data1.Q_AskPrice <= 0 || Data1.Q_BidPrice <= 0) Return;
      If(Data0.Q_BidPrice == Data0.Q_UpperLimit || Data0.Q_AskPrice == Data0.Q_LowerLimit) Return;
      If(Data1.Q_BidPrice == Data1.Q_UpperLimit || Data1.Q_AskPrice == Data1.Q_LowerLimit) Return;

      SpreadUpper = Data0.Q_AskPrice-Data1.Q_BidPrice;
      SpreadLower = Data0.Q_BidPrice-Data1.Q_AskPrice;
    // WWW.CXH99.COM
      bTimeCon = true;//Time>0.0903 ;//And (Time<0.1127 Or Time>0.1333) And Time<0.1456;
      bLongEntryCon = (SpreadUpper<=LongEntryPrice) && (Data0.Q_AskVol>=EveryLots && Data1.Q_BidVol>=EveryLots);
      bLongExitCon = (SpreadLower>=LongExitPrice) && (Data1.Q_AskVol>=EveryLots && Data0.Q_BidVol>=EveryLots);  
      bShortEntryCon = (SpreadLower>=ShortEntryPrice) && (Data1.Q_AskVol>=EveryLots && Data0.Q_BidVol>=EveryLots);
      bShortExitCon = (SpreadUpper<=ShortExitPrice) && (Data0.Q_AskVol>=EveryLots && Data1.Q_BidVol>=EveryLots);
      If(((bLongExitCon And bTimeCon And longPosition>0) Or longPosition>LongEndLots ))
      {
       Data0.A_SendOrder(Enum_Sell,Enum_Exit,Data0Lots,Data0.Q_BidPrice-OffsetPoint*MinMove*PriceScale);
       Data1.A_SendOrder(Enum_Buy,Enum_Exit,Data1Lots,Data1.Q_AskPrice+OffsetPoint*MinMove*PriceScale);
       SetGlobalVar(0,longPosition - EveryLots);
      }

      If(((bShortExitCon And bTimeCon And shortPosition>0) Or shortPosition>ShortEndLots ))
      {
       Data0.A_SendOrder(Enum_Buy,Enum_Exit,Data0Lots,Data0.Q_AskPrice+OffsetPoint*MinMove*PriceScale);
       Data1.A_SendOrder(Enum_Sell,Enum_Exit,Data1Lots,Data1.Q_BidPrice-OffsetPoint*MinMove*PriceScale);
       SetGlobalVar(1,shortPosition - EveryLots);
      }
    //www.cxh99.com
      If((bLongEntryCon And bTimeCon And longPosition<LongEndLots))
      {
       Data0.A_SendOrder(Enum_Buy,Enum_Entry,Data0Lots,Data0.Q_AskPrice+OffsetPoint*MinMove*PriceScale);
       Data1.A_SendOrder(Enum_Sell,Enum_Entry,Data1Lots,Data1.Q_BidPrice-OffsetPoint*MinMove*PriceScale);
       SetGlobalVar(0,longPosition + EveryLots);
      }
      
      If(( bShortEntryCon And bTimeCon And shortPosition<ShortEndLots))
      {
       Data0.A_SendOrder(Enum_Sell,Enum_Entry,Data0Lots,Data0.Q_BidPrice-OffsetPoint*MinMove*PriceScale);
       Data1.A_SendOrder(Enum_Buy,Enum_Entry,Data1Lots,Data1.Q_AskPrice+OffsetPoint*MinMove*PriceScale);
       SetGlobalVar(1,shortPosition + EveryLots);
      }
    }
    Commentary("多头仓位="+Text(longPosition));
    Commentary("空头仓位="+Text(shortPosition));
    End

[url=http://www.70822.com/soft/sort013/sort083/down-59384.html]开拓者 TB 强悍的全局变量功能 及 源码范例 想成为开拓者高手必看[/url]

关于本站 | 网站帮助 | 广告合作 | 声明 | 友情连接 | 网站地图 |
分析家公式网声明:本站所有股票公式软件资料均网上公开收集,如侵权请联系删帖。站内所有广告,均与本站无关!
Copyright © 2003-2024 70822.Com. All Rights Reserved .
页面执行时间:62.50000 毫秒