Params
//此处添加参数
Numeric length(30);
Vars
//此处添加变量
Numeric avg;
Global Integer timerId;
Series<Numeric> bar_in_day;
Series<Numeric> highest_in_day;
Series<Numeric> lowest_in_day;
Series<Numeric> trade_count;
Bool isFirstDay(false); // 标记是否为数据集的第一天
Defs
Events
//此处实现事件函数
OnInit()
{
isFirstDay = true;
}
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<Integer> indexs)
{
if(TrueDate(0)<>TrueDate(1) || isFirstDay)
{
bar_in_day = 0;
highest_in_day = high;
lowest_in_day = low;
}
bar_in_day = bar_in_day + 1;
Commentary(\"当天第几根bar:\"+text(bar_in_day));
If(bar_in_day <= length)
{
highest_in_day = max(highest_in_day,high);
lowest_in_day = min(lowest_in_day,low);
}
//PlotNumeric(\"low:\",low);
PlotNumeric(\"highest_in_day:\",highest_in_day);
PlotNumeric(\"lowest_in_day:\",lowest_in_day);
}
这段代码是在k线中显示当天最低和最高价,但是第一天的最低价总是为0,是什么原因?
isfirstday 跨域使用的话,要定义成global 否则无法传递
而且你isfisrtday,是不是得首根bar判断成功以后关掉这个变量呢?不需要对状态变量作控制的吗