Download MetaTrader 5

problem of initialization of custom indicator buffer?

To add comments, please log in or register
YYY
24
YYY  

 Build 244

According to the help file of function "

ArrayInitialize", it says that "It's not recommended to initialize index buffers in the OnInit() function of custom indicators, because they are automatically initialized byEMPTY_VALUE when buffers are distributed and re-distributed."

But when I used the code below, from chart window and data window I found default value of indicator buffer is 0, not EMPTY_VALUE.

What the problem is?

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//---- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
   int i;
   for(i=rates_total-20;i<rates_total-10;i++)
      {
       Label1Buffer[i]=1;
      }
   return(rates_total);
  }
To add comments, please log in or register