- 精华
- 20
- 在线时间
- 2981 小时
- UID
- 4
- 积分
- 22709
- 帖子
- 4802
- 阅读权限
- 255
- 注册时间
- 2007-7-20
- 最后登录
- 2024-1-15
- 精华
- 20
- UID
- 4
- 积分
- 22709
- 帖子
- 4802
- 主题
- 64
- 阅读权限
- 255
- 注册时间
- 2007-7-20
- 最后登录
- 2024-1-15
|
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
复制代码
|
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
-
总评分: 威望 + 12
查看全部评分
|