Array access problems when converting mql4 to mql5

 

Hi, i have an two error about the array when i converting mql4 codes to mql5, can anyone help me, when i fix those according to mql document, it seems again (most probably i miss something). I shared the codes below. Thanks in advance.

i declare HT1 array like this : 

double HT1[][4];

First problem is : invalid array access problem for the HT1 array : 


            for(i=0;i<4;i++){

               qTL=NormalizeDouble(qLevel+HT[i],qPoint);

               HT1[i]=NormalizeDouble(qLevel+HT[i],qPoint); //error in this line

             }


Second problem is : parameter conversion not allowed for the HT1 array : 

error in this line, when i called the function like this : 

GetSortedArrayDesc(HT1);


and the function : 

void GetSortedArrayDesc[4](double &d[4])
{
   
   for (int i = 0 ; i < 4; i++)
   {
      for (int j = i ; j < 4; j++)
      {
         if(d[j] < d[i])
         {
            double dumi = d[i];
            d[i] = d[j];
            d[j]= dumi;
         }
      }      
   }    
}
Documentation on MQL5: Language Basics / Variables
Documentation on MQL5: Language Basics / Variables
  • www.mql5.com
Variables - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
  1. Rabia Yoruk: First problem is : invalid array access problem for the HT1 array : 
    double HT1[][4];
    ⋮
                   qTL=NormalizeDouble(qLevel+HT[i],qPoint);
    
                   HT1[i]=NormalizeDouble(qLevel+HT[i],qPoint); //error in this line

    You declared a two-dimensional (2D) array and then are trying to access it as a 1D array.

  2. Rabia Yoruk
    void GetSortedArrayDesc[4](double &d[4])

    A function call is not an array. You pass a 2D array to a parameter declared as 1D.

 

How about using the MQL5 array functions instead of rolling your own:

// GetSortedArrayDesc(HT1);
ArraySort(HT1); // sort ascending order
ArrayReverse(HT1); // descending order
 
William Roeder:
  1. You declared a two-dimensional (2D) array and then are trying to access it as a 1D array.

  2. A function call is not an array. You pass a 2D array to a parameter declared as 1D.

thank you for your reply, when i fix the those problems like below, it is fixed now.

double HT1[4],LT1[4];
 
lippmaje:

How about using the MQL5 array functions instead of rolling your own:

thanks for your reply too, i convert my funcs to what your said however the error is 'ArrayReverse' - function not defined , so mql5 doesnt recognize the ArrayReverse function in my indicator.


 
Rabia Yoruk:

thanks for your reply too, i convert my funcs to what your said however the error is 'ArrayReverse' - function not defined , so mql5 doesnt recognize the ArrayReverse function in my indicator.

It's also available in MQL 5, see https://www.mql5.com/en/docs/array/array_reverse.

Show your code if it doesn't compile.

Documentation on MQL5: Array Functions / ArrayReverse
Documentation on MQL5: Array Functions / ArrayReverse
  • www.mql5.com
ArrayReverse - Array Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: