Another problem with indicators buffers (variation)

 

#property copyright ""
#property link      ""
#property version   "1.00"
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_plots 2
#property  indicator_color1  Silver
#property  indicator_color2  Silver
#property  indicator_width1  2
#property  indicator_width2  2

double     MacdBuffer[];
double buf2[];
int        handle;

int OnInit()
  {
   SetIndexBuffer(0,MacdBuffer,INDICATOR_DATA);
   //SetIndexBuffer(1, buf2, INDICATOR_DATA);
   PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
   PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE);
   handle=iMA(NULL,0,26,0,MODE_EMA,PRICE_CLOSE);
   return(0);
}
 
double x[];
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[])
  {
   for(int i = 0; i < ArraySize(buf2); i++) buf2[i] = 0.0;
 
   int count = rates_total - prev_calculated;
   int delta = ArraySize(MacdBuffer)-ArraySize(x);
   for(int i = 0; i < ArraySize(x); i++) MacdBuffer[i+delta] = x[i];
   ArrayResize(x, rates_total);
  
   double buf[1];
   int t = BarsCalculated(handle);
   for(int i = 0; i < count; i++) {
      CopyBuffer(handle, 0, t-i-1, 1, buf);
      MacdBuffer[i] = buf[0];
   }

   for(int i = 0; i < ArraySize(x); i++) x[i] = MacdBuffer[i];
   return(rates_total);
}

I don't know why, but uncommenting this line (without any other changes)

//SetIndexBuffer(1, buf2, INDICATOR_DATA); 

Changes this

 

into this 

 

It seems that the problem/bug https://www.mql5.com/en/forum/2092 isn't really solved, saving the array just fixes it by accident. Either mql5 is buggy and developers don't care (giving incorrent reply and ignoring afterwards), or I'm too stupid to understand it.

Why enabling one buffer as indicator changes the value of another? And how to fix this?

 

Enabling doesn't change values of another buffer. It seems like this, but it doesn't. You can check it in Data Window.

What exactly are you trying to do in your indicator?

Have you read article MQL5: Create Your Own Indicator?


 

Thank you! You are right.

I didn't realize scaling make it look thay way :/ Shame 

Reason: