一个关于基础数据使用的问题

// 简称: RolloverInfo // 名称: 显示换月除权信息 // 类别: 公式应用 // 类型: 内建应用 这是系统内建的显示除权信息的公式,遇到一个诡异的问题。 这样是可以正常显示除权信息的。但是,只要在代码中加一行计算语句,比如 MID1 = StandardDev(CLOSE,M); 发现,前面几个除权的信息,就不显示了,消失了。 有的计算不会影响,比如 xaverage 更多的影响 比如,highest average averagefc standarddev 等等等等。请帮忙看看,这是什么情况。

@kyover ,您好。 请问,我在 OnInit() 域中加入了 SetBeginBarMaxCount(10); 但是并没有效果,绘图、逻辑判断依然是从 CurrentBar == 100 的位置开始生效的。 请问是我哪里操作不对么? //------------------------------------------------------------------------ // 简称: RolloverInfo // 名称: 显示换月除权信息 // 类别: 公式应用 // 类型: 内建应用 //------------------------------------------------------------------------ Vars //期货 Dic<Array<String>> fRollover("TB_ROLLOVER"); //[期货换月合约,期货换月前价格,期货换月后价格] //股票 Dic<Array<Numeric>> sXDXR("TB_XDXR"); //[每股送股,配股比例,配股价格,每股派现金,收盘价] Plot plt; Numeric mid1; Numeric m(100); Events OnInit() { Range[0:DataCount - 1] { plt.setOption("rollover","x-format","time"); plt.setOption("rollover","margin-top","99%"); plt.setOption("rollover","margin-bottom","95%"); //AddDataFlag(Enum_Data_RolloverBackWard()); //设置后复权 } SetBeginBarMaxCount(10); } OnBar(ArrayRef<Integer> indexs) { Commentary("CurrentBar = "+text(CurrentBar)); MID1 = Average(CLOSE,m); PlotAuto("mid1",mid1,mid1); PlotBool("test1",c>o,high); Range[0:DataCount - 1] { Integer cgy = Category(); If(cgy == 1) //期货换月 { If(GetDicTime(fRollover, 0) <> GetDicTime(fRollover, 1) And fRollover[0][1] <> InvalidString And fRollover[0][2] <> InvalidString) { String tooltips = "换月前价格:"+fRollover[0][1]+ "\n换月后价格:"+fRollover[0][2]; plt.icon("rollover",date+time,InvalidInteger,"xinghao",tooltips); //PlotAuto("con",False,low); //在bar的最高价位置输出条件con的布尔值。 } } Else If(cgy == 0) //股票除权 { If(GetDicTime(sXDXR, 0) <> GetDicTime(sXDXR, 1) And (sXDXR[0][0] <> InvalidNumeric Or (sXDXR[0][1] <> InvalidNumeric And sXDXR[0][2] <> InvalidNumeric) Or sXDXR[0][3] <> InvalidNumeric Or sXDXR[0][4] <> InvalidNumeric) And sXDXR[0][5] <> InvalidNumeric) { String tooltips = "发布时间:"+Text(UTC2Local(sXDXR[0][0])) + IIFString(Text(sXDXR[0][1]) == InvalidString,"","\n每十股送股:"+ Text(sXDXR[0][1] * 10) + "股") + IIFString(Text(sXDXR[0][2]) == InvalidString,"","\n配股比例:"+ Text(sXDXR[0][2])) + IIFString(Text(sXDXR[0][3]) == InvalidString,"","\n配股价格:"+ Text(sXDXR[0][3])) + IIFString(Text(sXDXR[0][4]) == InvalidString,"","\n每十股红利:"+ Text(sXDXR[0][4] * 10) + "元") + IIFString(Text(sXDXR[0][5]) == InvalidString,"","\n股票除权前价格:"+ Text(sXDXR[0][5])); plt.icon("rollover",date+time,InvalidInteger,"xinghao",tooltips); } } } } //------------------------------------------------------------------------ // 编译版本 GS2014.10.25 // 版权所有 TradeBlazer Software 2003-2025 // 更改声明 TradeBlazer Software保留对TradeBlazer平 // 台每一版本的TradeBlazer公式修改和重写的权利 //------------------------------------------------------------------------

回复:跟开发人员讨论了一下,现在第二种方案解决不了了,你要么试试把这个计算加权平均和rolloverinfo不要写在同一个公式里,就不会触发这个机制了

麻烦技术帮忙看一下。

回复:如果一定要解决这个问题,由两种方案,第一 样本数量加载多一点,让有效样本区间避开最初始的100根。第二,SetBeginBarMaxCount用这个函数强制公式从设定的数量开始运行计算和作图。但是第二种方法由计算不准确的风险,原因上面说过了

回复:好的,非常感谢,我用第二种方案试试。

回复:

建议贴上完整代码 可变部分用注释表示

回复:就是系统内建公式,原封不动,按F11会出现的那个 //------------------------------------------------------------------------ // 简称: RolloverInfo // 名称: 显示换月除权信息 // 类别: 公式应用 // 类型: 内建应用 //------------------------------------------------------------------------ Vars //期货 Dic<Array<String>> fRollover("TB_ROLLOVER"); //[期货换月合约,期货换月前价格,期货换月后价格] //股票 Dic<Array<Numeric>> sXDXR("TB_XDXR"); //[每股送股,配股比例,配股价格,每股派现金,收盘价] Plot plt; Events OnInit() { Range[0:DataCount - 1] { plt.setOption("rollover","x-format","time"); plt.setOption("rollover","margin-top","99%"); plt.setOption("rollover","margin-bottom","95%"); //AddDataFlag(Enum_Data_RolloverBackWard()); //设置后复权 } } OnBar(ArrayRef<Integer> indexs) { Range[0:DataCount - 1] { Integer cgy = Category(); If(cgy == 1) //期货换月 { If(GetDicTime(fRollover, 0) <> GetDicTime(fRollover, 1) And fRollover[0][1] <> InvalidString And fRollover[0][2] <> InvalidString) { String tooltips = "换月前价格:"+fRollover[0][1]+ "\n换月后价格:"+fRollover[0][2]; plt.icon("rollover",date+time,InvalidInteger,"xinghao",tooltips); } } Else If(cgy == 0) //股票除权 { If(GetDicTime(sXDXR, 0) <> GetDicTime(sXDXR, 1) And (sXDXR[0][0] <> InvalidNumeric Or (sXDXR[0][1] <> InvalidNumeric And sXDXR[0][2] <> InvalidNumeric) Or sXDXR[0][3] <> InvalidNumeric Or sXDXR[0][4] <> InvalidNumeric) And sXDXR[0][5] <> InvalidNumeric) { String tooltips = "发布时间:"+Text(UTC2Local(sXDXR[0][0])) + IIFString(Text(sXDXR[0][1]) == InvalidString,"","\n每十股送股:"+ Text(sXDXR[0][1] * 10) + "股") + IIFString(Text(sXDXR[0][2]) == InvalidString,"","\n配股比例:"+ Text(sXDXR[0][2])) + IIFString(Text(sXDXR[0][3]) == InvalidString,"","\n配股价格:"+ Text(sXDXR[0][3])) + IIFString(Text(sXDXR[0][4]) == InvalidString,"","\n每十股红利:"+ Text(sXDXR[0][4] * 10) + "元") + IIFString(Text(sXDXR[0][5]) == InvalidString,"","\n股票除权前价格:"+ Text(sXDXR[0][5])); plt.icon("rollover",date+time,InvalidInteger,"xinghao",tooltips); } } } } //------------------------------------------------------------------------ // 编译版本 GS2014.10.25 // 版权所有 TradeBlazer Software 2003-2025 // 更改声明 TradeBlazer Software保留对TradeBlazer平 // 台每一版本的TradeBlazer公式修改和重写的权利 //------------------------------------------------------------------------ 触发这个现象的代码是, 定义变量 Numeric mid1; Numeric m(100); onbar里加上 MID1 = Average(CLOSE,m); 就会出现图中的现象了。 在 currentbar < M 的范围内的复权信息,就都不显示了。

回复:这是TB的回溯机制导致的。TB会自动检测代码里所有的需要回溯的函数,比如average,xaverage,highest这类函数,找这些函数里需要回溯的最大数量。 比如公式里出现average(close,20) highest(high,30),那么系统就自动判定,该公式最大回溯数量为highest里的30。 判断出来以后,系统在图表的最初30根k线上,不做计算,不画图。 这种处理的原因,主要是因为,这类需要回溯计算的指标,如果k线数量不够,计算出来的指标都是不准确的。为了保证模型内所有指标激计算正确,需要向上面一样强制过滤掉图表最开始的部分k线。 你这个案例里,因为加入了一个函数,导致回溯数量变成了m,那么自然前m根k线上,不会进行任何作图处理了。

回复:就是说,回溯机制并不是针对不同函数分开生效的,是以回溯数量最大的那个函数为准,其它不需要回溯的功能也受到影响? 我简单试了一下,类似 close>open 这样的逻辑判断,也没有返回值了。但是 类似 average(high,m)这样的函数,在M根bar以前,反而一直是有返回值的。

回复:函数代码还是会执行,但是会强制把plot还有图标交易信号等可以在图上画出东西的命令强制取消。就是东西都计算出来了,就是不画而已,