Error 4029 Invalid array

 

Hi all.

 

So i have this indicator to calculate Swings it's working just fine in all charts and in all time frames... all but one CHFJPY on 1D time frame. it gives me Error 4029 Invalid Array.

what happens is that all calculations are done normally inside OnCalculate() but for some reason i get this error. When i change time frame it works fine again.

Any ideia? 

double Indicador[];
int I, Swing_Begin, Swing_End;
string Swing;
int OnInit()
{  
   SetIndexBuffer(0,Indicador);                          // Assigning an array to a buffer
   SetIndexStyle (0,DRAW_HISTOGRAM,STYLE_SOLID,5);       // Line style
                                                           
   return(INIT_SUCCEEDED);
} 
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[] )  
{
   if (prev_calculated == 0)
   { 
      ArrayResize(Indicador, rates_total - 1);              // Update Array Size.
                                                            
      Swing_Begin = rates_total - 1;                        
      Swing_End   = rates_total - 1;                       
      
      if (open[rates_total - 1] > close[rates_total - 1])  Swing = "DESC";
      else                                                 Swing = "ASC";
      
      Comment(GetLastError());
   }
 
   ArrayResize(Indicador, rates_total - 1);              // Update Array Size.

Indicador is a buffer, you cannot re-size it

How can this indicator be working fine? It doesn't do anything 

 
It works great indeed. It tells me whether we are in a 

Asc swing or Desc swing (flowless)

 

I already deleted that statement before came here and it's the same thing. 

 
From what i have read since you declare array[100] for exemple you can re-size it. Even a buffer.
 
 
Check it
 
bro840:
Check it

It is not possible that your image shows the same indicator that you have posted the code for.

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[] )  
{
   if (prev_calculated == 0)
   { 
      ArrayResize(Indicador, rates_total - 1);              // Update Array Size.
                                                            
      Swing_Begin = rates_total - 1;                        
      Swing_End   = rates_total - 1;                       
      
      if (open[rates_total - 1] > close[rates_total - 1])  Swing = "DESC";
      else                                                 Swing = "ASC";
      
      Comment(GetLastError());
   }

 You don't assign any values to the buffer at all

 

Of course not it give me a lot of hard work to make it happen....

 

But the error it's not in the calculations it's right in the begining, because when a call GetLastError() the error is there already

 
I've already told you the error, you cannot re-size buffers.
 
double Indicador[];
int I, Swing_Begin, Swing_End;
string Swing;


int OnInit()
{  
   SetIndexBuffer(0,Indicador);                          // Assigning an array to a buffer
   SetIndexStyle (0,DRAW_HISTOGRAM,STYLE_SOLID,5);       // Line style
                                                           
   return(INIT_SUCCEEDED);
}




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[] )  
{
   if (prev_calculated == 0)
   {                                      
      Swing_Begin = rates_total - 1;                        
      Swing_End   = rates_total - 1;                        
      
      if (open[rates_total - 1] > close[rates_total - 1])  Swing = "DESC";
      else                                                 Swing = "ASC";
      
      Comment(GetLastError());
   }
i get the same error
 

I tested with the original code that you posted.

Remove the ArrayResize and GetLastError() returns 0. 

Reason: