Custom Indicator Buffer returning EMPTY_VALUE

 

Hello,

I'm populating the previous 5 indexes of a custom buffer every 5 minutes via a function which I am calling like so:


#property indicator_buffers 12
#property indicator_chart_window

double ExtBuffer1[];

int OnInit(void)
{
   SetIndexBuffer(0,ExtBuffer1);
}

void updateBuffer(double &buf[], const int lower_tf, const int upper_tf, const int shift)
{
        for(int i=shift+(upper_tf/lower_tf); i>= shift; i--)
                buf[i] = MathRand()*1000;
}

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 lookback = 100;
   int limit = Bars - 1 - MathMax(lookback, prev_calculated);
   for(int i = limit; i >= 0 && !IsStopped(); --i)
     {
	bool newbar_M5 = aNewBarEVENT(_Symbol,5);
	if(newbar_M5)
        	updateBuffer(ExtBuffer1[], 1, 5, i);
     }
   PrintFormat(__FUNCTION__+", ExtBuffer1[%i] = %f",i,ExtBuffer1[i]);
   return rates_total -1;
}

But everytime I use the buffer I'm getting the value 2147483647.000000 being returned from the buffer which is EMPTY_VALUE in my case.

What am I doing wrong please? 


 

I've done some further research and the problems seems to be coming from the fact that I update the buffers in the same loop cycle. I've issued a RefreshRates() but that is returning false, so my questions are:

How do I update the buffers in the same loop cycle and have them updated? And, why is RefreshRates() returning false?

Thanks again.

 
Fixed it by adding a update buffers loop cycle the and process buffers loop cycle!