Download MetaTrader 5

Another problem with indicators buffers (variation)

To add comments, please log in or register
How to test a program before buying?
mqltools 2010.09.22 13:04 

#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(1, buf2, INDICATOR_DATA);
   PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
   PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE);
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];

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 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?

Alexey Da
Alexey Da 2010.09.22 14:41  

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?

mqltools 2010.09.22 22:38  

Thank you! You are right.

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

To add comments, please log in or register