Download MetaTrader 5
To add comments, please log in or register
Traders have already contributed more than 300 articles. Write your own one!
simoncs
321
simoncs 2014.07.31 12:16 

Hi

 

I am getting an error message - IgnoreArray - invalid array access - on this .mqh file, when trying to compile it. Is it possibly related to the changes that came with v600?I can't seem to find enough info on the eror message to help me work out what the problem is. I am hoping to use this code posted by another member to use for reporting purposes. I can get most of the mqh to work without this component.

 Also - I can't find what "int& IgnoreArray[]"  means -  what does the "&" symbol mean? 

 

I have added the whole file if necessary.

thanks 

 

 

int IdentifyTradesToIgnore(double DataArray[],int& IgnoreArray[])
   {
   int      recentindex,i,candidateindex;
   double   MathAvgOnArray,MathStdDevOnArray;
   
   
   // DataArray - identify outliers beyond +/- 8.5 sigma (99.9% CI based on generalized distribution)
   if(ArrayRange(DataArray,0)<3) 
   return(IgnoreArray); // if there are few members of the data array then return without calculation
   
   MathAvgOnArray=MathAvg(DataArray);
   MathStdDevOnArray=MathStdev(DataArray);
   recentindex=0; // reset index position for IgnoreArray searches
   for(i=0;i<ArrayRange(DataArray,0);i++)
      {
      if(DataArray[i]<(MathAvgOnArray-8.5*MathStdDevOnArray) || DataArray[i]>(MathAvgOnArray+8.5*MathStdDevOnArray))
         {
         // check to see if whether or not trade order "i" was previously identified and logged as an excursion trade
         candidateindex=ArrayBsearch(IgnoreArray,i,WHOLE_ARRAY,recentindex,MODE_ASCEND);
         if(IgnoreArray[candidateindex]==i+1)
            {
            recentindex=candidateindex;
            continue; // return to the next outermost loop because we already know the existing i is a documented excursion trade
            }
         if(IgnoreArray[ArrayRange(IgnoreArray,0)-1]==-1)
            {
            IgnoreArray[0]=i+1;
            recentindex=MathMax(recentindex-1,0);  // back-up the recentindex by 1
            continue;
            }
         ArrayResize(IgnoreArray,ArrayRange(IgnoreArray,0)+1);
         IgnoreArray[ArrayRange(IgnoreArray,0)-1]=i+1;
         ArraySort(IgnoreArray,WHOLE_ARRAY,0,MODE_ASCEND);   // sort the array so the most recently appended trade order number is properly indexed
         recentindex=MathMax(recentindex-1,0);  // back-up the recentindex by 1
         }
      }
   return(IgnoreArray);
   }
Drazen Penic
2404
Drazen Penic 2014.07.31 13:16  

Arrays are always passed by reference. You have to add "&" for the first array also:

 

int IdentifyTradesToIgnore(double& DataArray[],int& IgnoreArray[])

 

 For explanation and examples see documentation: Passing Parameters 

simoncs
321
simoncs 2014.08.02 05:31  
drazen64:

Arrays are always passed by reference. You have to add "&" for the first array also:

 

 

 For explanation and examples see documentation: Passing Parameters 


thanks for that info.

 

unfortunately it doesn't seem to fix the issue though. I still get the same error message. 

Drazen Penic
2404
Drazen Penic 2014.08.02 08:05  

I downloaded your code, but it can't be compiled because there are additional files included.

Add "&" infront of arrays in all your function definitions. 

Below you try to return an array as function result. It can't be done, and besides that type of function result is int, so you can return only one element of the array: return(IgnoreArray[some_idx]);

 

int IdentifyTradesToIgnore(double DataArray[],int& IgnoreArray[])
   {
   int      recentindex,i,candidateindex;
   double   MathAvgOnArray,MathStdDevOnArray;
   
   
   // DataArray - identify outliers beyond +/- 8.5 sigma (99.9% CI based on generalized distribution)
   if(ArrayRange(DataArray,0)<3) 
   return(IgnoreArray); // if there are few members of the data array then return without calculation
   
   MathAvgOnArray=MathAvg(DataArray);
   MathStdDevOnArray=MathStdev(DataArray);
   recentindex=0; // reset index position for IgnoreArray searches
   for(i=0;i<ArrayRange(DataArray,0);i++)
      {
      if(DataArray[i]<(MathAvgOnArray-8.5*MathStdDevOnArray) || DataArray[i]>(MathAvgOnArray+8.5*MathStdDevOnArray))
         {
         // check to see if whether or not trade order "i" was previously identified and logged as an excursion trade
         candidateindex=ArrayBsearch(IgnoreArray,i,WHOLE_ARRAY,recentindex,MODE_ASCEND);
         if(IgnoreArray[candidateindex]==i+1)
            {
            recentindex=candidateindex;
            continue; // return to the next outermost loop because we already know the existing i is a documented excursion trade
            }
         if(IgnoreArray[ArrayRange(IgnoreArray,0)-1]==-1)
            {
            IgnoreArray[0]=i+1;
            recentindex=MathMax(recentindex-1,0);  // back-up the recentindex by 1
            continue;
            }
         ArrayResize(IgnoreArray,ArrayRange(IgnoreArray,0)+1);
         IgnoreArray[ArrayRange(IgnoreArray,0)-1]=i+1;
         ArraySort(IgnoreArray,WHOLE_ARRAY,0,MODE_ASCEND);   // sort the array so the most recently appended trade order number is properly indexed
         recentindex=MathMax(recentindex-1,0);  // back-up the recentindex by 1
         }
      }
   return(IgnoreArray);
   }

 

There is a lots of code. If you don't have experience with MQL4, your best bet would be to hire someone to do it in freelance section

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.08.02 08:55  
simoncs:


thanks for that info.

 

unfortunately it doesn't seem to fix the issue though. I still get the same error message. 

Make your function type void . . . and read this:  https://www.mql5.com/en/forum/140349
/
To add comments, please log in or register