新增功能——通过文件读写函数实现跨周期数据调用

Discussion in '开拓者期货自动交易平台' started by tianlan203, Apr 15, 2009.

  1. TB3.2.2增加了文件读写功能函数,SetTBProfileString和GetTBProfileString,
    通过使用这两个函数,可以实现较复杂的应用,比如跨周期数据调用。
    SetTBProfileString将数据内容写到用户公式目录tblprofile.ini文件下。


    下文以5分钟周期调用日线指标数据举例讲解具体应用。

    操作步骤如下:
    1、新建一个工作区,包含上下两个图表窗体,上面选择日线周期,下面选择5分钟周期。
    2、新建一个技术指标,命名为MyDayMA。编译成功后插入日线图表中。详细代码如下:


    Params
    Numeric length(10);
    Vars
    Numeric MA;
    string strkey;
    string strValue;
    Begin
    MA = AverageFC(Close,length);
    strKey = DateToString(Date);
    strValue = Text(MA);
    SetTBProfileString("DayMA",strKey,strValue);
    PlotNumeric("MA",MA);
    End

    3、新建一个技术指标,My5MinMA。编译成功后插入5分钟图表中,详细代码如下:


    Vars
    NumericSeries DayMAValue;
    string strKey;
    string strValue;
    Begin
    strKey = DateToString(Date);
    strValue = GetTBProfileString("DayMA",strKey);
    If(strValue != InvalidString)
    {
    DayMAValue = Value(strValue);
    }Else
    {
    DayMAValue = DayMAValue[1];
    }
    PlotNumeric("DayMA",DayMAValue);
    End

    4、上面的指标实际使用了未来数据,用来写指标是可以的,但用来做交易指令进行自动交易就会出问题,为了更准确合理的使用跨周期数据,我们应该稍作修改,代码如下:


    Vars
    NumericSeries DayMAValue;
    StringSeries strKey;
    string strValue;
    Begin
    If(Date!=Date[1])
    {
    strKey = DateToString(Date[1]);
    }Else
    {
    strKey = strKey[1];
    }

    strValue = GetTBProfileString("DayMA",strKey);
    If(strValue != InvalidString)
    {
    DayMAValue = Value(strValue);
    }Else
    {
    DayMAValue = DayMAValue[1];
    }
    PlotNumeric("DayMA",DayMAValue);
    End
    [​IMG]
     
  2. TB的代码是类B、类C还是类Pascal?
     
  3. 都不类,搞个画虎不成反类X。
     
  4. 类Pascal
     
  5. 除了程序主体的BEGIN和END,其他基本都类C
     
  6. 开拓者期货自动交易平台是c++还是delphi编写的?
     
  7. c++