#property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //---- 图的编号 #property indicator_label1 "Numeration" #property indicator_type1 DRAW_LINE #property indicator_color1 CLR_NONE //--- 指标缓冲区 double NumerationBuffer[]; //+------------------------------------------------------------------+ //| 自定义指标初始化函数 | //+------------------------------------------------------------------+ int OnInit() { //--- 自定义缓冲区绘图 SetIndexBuffer(0,NumerationBuffer,INDICATOR_DATA); //--- 为类似时间序列的缓冲区设置指标 ArraySetAsSeries(NumerationBuffer,true); //--- 设置数据窗口中显示的精确度 IndicatorSetInteger(INDICATOR_DIGITS,0); //--- 标识符数组名称在数据窗口中如何显示 PlotIndexSetString(0,PLOT_LABEL,"Bar #"); //--- return(0); } //+------------------------------------------------------------------+ //| 自定义指标重复函数 | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- 存储当前打开的零柱时间 static datetime currentBarTimeOpen=0; //--- 返回访问数组时间[] - 像时间序列一样 ArraySetAsSeries(time,true); //--- 如果零柱时间不同于已经存储的 if(currentBarTimeOpen!=time[0]) { //--- 从当前图表到图表深度列举所有柱 for(int i=rates_total-1;i>=0;i--) NumerationBuffer[i]=i; currentBarTimeOpen=time[0]; } //--- 为下次调用返回prev_calculated值 return(rates_total); } |