Indicator Buffer not displaying

 

Hi folks,

This is driving me mad!! I'm creating an indicator that uses 4 buffers to be diaplayed. Unfortunately only 3 out of the 4 display. Here's a simplified version of the code. I'd greatly appreciate any advice.

Thanks in advance!

//+---------------------------------------------------------------------+
//| Buffer_Test.mq4 |
//| |
//| |
//+---------------------------------------------------------------------+
#property copyright ""
#property link ""

#property indicator_chart_window


#property indicator_buffers 4

#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Green
#property indicator_color4 DarkGreen


//---- buffers
double MA_1[];
double MA_2[];
double MA_3[];
double MA_4[];


extern int MA_1_Period = 10;
extern int MA_2_Period = 20;
extern int MA_3_Period = 50;
extern int MA_4_Period = 100;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{


SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MA_1);
SetIndexLabel(0,"MA_1");

SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,MA_2);
SetIndexLabel(1,"MA_2");

SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,MA_3);
SetIndexLabel(2,"MA_3");

SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,MA_4);
SetIndexLabel(3,"MA_4");


return(0);
}



//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{


int counted_bars = IndicatorCounted();
if(counted_bars < 0) return;
if(counted_bars > 0) counted_bars--;
int Limit = Bars - counted_bars;


for (int i= Limit; i >= 0; i--) // Main indicator FOR loop
{

MA_1[i] = iMA(Symbol(),0,(MA_1_Period),0,MODE_EMA,PRICE_CLOSE,i);
MA_2[i] = iMA(Symbol(),0,(MA_2_Period),0,MODE_EMA,PRICE_CLOSE,i);
MA_3[i] = iMA(Symbol(),0,(MA_3_Period),0,MODE_EMA,PRICE_CLOSE,i);
MA_4[i] = iMA(Symbol(),0,(MA_4_Period),0,MODE_EMA,PRICE_CLOSE,i);


}

return(0);
}


 
Catan wrote >>

Hi folks,

This is driving me mad!! I'm creating an indicator that uses 4 buffers to be diaplayed. Unfortunately only 3 out of the 4 display. Here's a simplified version of the code. I'd greatly appreciate any advice.

Thanks in advance!

//+---------------------------------------------------------------------+
//| Buffer_Test.mq4 |
//| |
//| |
//+---------------------------------------------------------------------+
#property copyright ""
#property link ""

#property indicator_chart_window


#property indicator_buffers 4

#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Green
#property indicator_color4 DarkGreen


//---- buffers
double MA_1[];
double MA_2[];
double MA_3[];
double MA_4[];


extern int MA_1_Period = 10;
extern int MA_2_Period = 20;
extern int MA_3_Period = 50;
extern int MA_4_Period = 100;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{


SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MA_1);
SetIndexLabel(0,"MA_1");

SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,MA_2);
SetIndexLabel(1,"MA_2");

SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,MA_3);
SetIndexLabel(2,"MA_3");

SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,MA_4);
SetIndexLabel(3,"MA_4");


return(0);
}



//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{


int counted_bars = IndicatorCounted();
if(counted_bars < 0) return;
if(counted_bars > 0) counted_bars--;
int Limit = Bars - counted_bars;


for (int i= Limit; i >= 0; i--) // Main indicator FOR loop
{

MA_1[i] = iMA(Symbol(),0,(MA_1_Period),0,MODE_EMA,PRICE_CLOSE,i);
MA_2[i] = iMA(Symbol(),0,(MA_2_Period),0,MODE_EMA,PRICE_CLOSE,i);
MA_3[i] = iMA(Symbol(),0,(MA_3_Period),0,MODE_EMA,PRICE_CLOSE,i);
MA_4[i] = iMA(Symbol(),0,(MA_4_Period),0,MODE_EMA,PRICE_CLOSE,i);


}

return(0);
}



I normally include SetIndexDrawBegin and SetIndexStyle commands for each buffer, but that doesn't explain why three of then work already. Two other things that come to mind: are there any log entries that could shed light on the problem? Also, a 100 bar EMA will sometimes be completely off-screen during fast trends.


Paul
 
phampton wrote >>

I normally include SetIndexDrawBegin and SetIndexStyle commands for each buffer, but that doesn't explain why three of then work already. Two other things that come to mind: are there any log entries that could shed light on the problem? Also, a 100 bar EMA will sometimes be completely off-screen during fast trends.


Paul

Thanks Paul,

Funny thing, I woke up this morning and opened MetaTrader and the indicator was behaving fine with all 4 buffers being displayed. Strange! Maybe it was a memory issue or something along those lines, or possibly that I was working offline. God only knows!! Anyway, thanks for your response. I never used SetIndexDrawBegin before. That should help keeping the indicator work load down.
 

I had this expirience as well.

When you do any changes to the buffers of an indicator ALWAYS restart your terminal. Then everything should work fine...unless you did crap-coding :D

 
Next time don't paste you code, use the SRC button.
 
ErrorProgrammer wrote >>

I had this expirience as well.

When you do any changes to the buffers of an indicator ALWAYS restart your terminal. Then everything should work fine...unless you did crap-coding :D


Excellent, thanks!
Reason: