MQL4 Reference Array Functions ArrayCompare

MQL4 Help as One File:

ArrayCompare

The function returns the result of comparing two arrays of the same type. It can be used to compare arrays of simple types or custom structures without complex objects, that is the custom structures that do not contain strings, dynamic arrays, classes and other structures with complex objects.

int  ArrayCompare(
   const void&  array1[],            // first array
   const void&  array2[],            // second array
   int          start1=0,            // initial offset in the first array
   int          start2=0,            // initial offset in the second array
   int          count=WHOLE_ARRAY    // number of elements for comparison
   );

Parameters

array1[]

[in]  First array.

array2[]

[in]  Second array.

start1=0

[in]  The element's initial index in the first array, from which comparison starts. The default start index - 0.

start2=0

[in]  The element's initial index in the second array, from which comparison starts. The default start index - 0.

count=WHOLE_ARRAY

[in]  Number of elements to be compared. All elements of both arrays participate in comparison by default (count=WHOLE_ARRAY).

Returned value

  • -1, if array1[] less than array2[]
  • 0, if array1[] equal to array2[]
  • 1, if array1[] more than array2[]
  • -2, if an error occurs due to incompatibility of the types of compared arrays or if start1, start2 or count values lead to falling outside the array.

Note

The function will not return 0 (the arrays will not be considered equal) if the arrays differ in size and count=WHOLE_ARRAY for the case when one array is a faithful subset of another one. In this case, the result of comparing the sizes of that arrays will be returned: -1, if the size of array1[] is less than the size of array2[] , otherwise 1.