Download MetaTrader 5
To add comments, please log in or register
Read the interviews of the Automated Trading Championship participants
Bro840
104
Bro840 2016.02.10 22:32 

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());
   }
Keith Watford
Moderator
9543
Keith Watford 2016.02.10 22:44  
   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 

Bro840
104
Bro840 2016.02.10 22:48  
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. 

Bro840
104
Bro840 2016.02.10 22:50  
From what i have read since you declare array[100] for exemple you can re-size it. Even a buffer.
Bro840
104
Bro840 2016.02.10 22:56  
Bro840
104
Bro840 2016.02.10 22:56  
Check it
Keith Watford
Moderator
9543
Keith Watford 2016.02.10 23:15  
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

Bro840
104
Bro840 2016.02.10 23:17  

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

Keith Watford
Moderator
9543
Keith Watford 2016.02.10 23:29  
I've already told you the error, you cannot re-size buffers.
Bro840
104
Bro840 2016.02.10 23:31  
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
Keith Watford
Moderator
9543
Keith Watford 2016.02.11 00:02  

I tested with the original code that you posted.

Remove the ArrayResize and GetLastError() returns 0. 

/ /12
To add comments, please log in or register