DRAW_NONE

DRAW_NONE样式是专为需要计算缓冲区值和将其显示在数据窗口的情况下使用而设计的,但图表上的标图并不要求。若要建立精确性,请在OnInit()函数使用IndicatorSetInteger(INDICATOR_DIGITS,num_chars)表达式:

int OnInit()
  {
//--- 指标缓冲区映射
   SetIndexBuffer(0,InvisibleBuffer,INDICATOR_DATA);
//--- 设置显示在数据窗口的精确值
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//---
   return(INIT_SUCCEEDED);
  }

DRAW_NONE标图所需的缓冲区的数量是1。

在数据窗口,显示鼠标当前所悬停柱形数量的指标示例。编号对应时间帧,表示当前未完成的柱形有0标引,最早的柱形有最大的标引。

DRAW_NONE示例

注意,即使是事实,因为红色设置标图 №1,指标也不会在图表上绘制任何内容。

//+------------------------------------------------------------------+
//|                                                    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;
  }