//+------------------------------------------------------------------+ //| DRAW_NONE.mq5 | //| Copyright 2011, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2000-2024, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- 标图不可见 #property indicator_label1 "Bar Index" #property indicator_type1 DRAW_NONE #property indicator_style1 STYLE_SOLID #property indicator_color1 clrRed #property indicator_width1 1 //--- 指标缓冲区 double InvisibleBuffer[]; //+------------------------------------------------------------------+ //| 自定义指标初始化函数 | //+------------------------------------------------------------------+ int OnInit() { //--- 绑定数组和指标缓冲区 SetIndexBuffer(0,InvisibleBuffer,INDICATOR_DATA); //--- 设置展示在数据窗口的精确值 IndicatorSetInteger(INDICATOR_DIGITS,0); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 自定义指标迭代函数 | //+------------------------------------------------------------------+ 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 lastbar=0; //--- 如果这是指标的第一次计算 if(prev_calculated==0) { //--- 第一次重新编号柱形 CalcValues(rates_total,close); //--- 在lastbar记下当前柱的开盘时间 lastbar=(datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE); } else { //--- 如果新柱出现,其开盘时间不同于lastbar if(lastbar!=SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE)) { //--- 再次重新编号柱形 CalcValues(rates_total,close); //--- 在lastbar更新当前柱的开盘时间 lastbar=(datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE); } } //--- 返回prev_calculated值以便下次调用 return(rates_total); } //+------------------------------------------------------------------+ //| 编制类似时间帧的柱形编号 | //+------------------------------------------------------------------+ void CalcValues(int total,double const &array[]) { //--- 设置时间帧的指标缓冲区标引 ArraySetAsSeries(InvisibleBuffer,true); //--- 用其编号填写每个柱形 for(int i=0;i<total;i++) InvisibleBuffer[i]=i; } |