# ArraySort() in MQL5 - sorts in Descending order and not Ascending as documented?

90

I have probably misunderstood the documention for the ArraySort() function in MQL5.

https://www.mql5.com/en/docs/array/arraysort states "Sorts the values in the first dimension of a multidimensional numeric array in the ascending order".

When I use this function, my arrays are sorted with Array[0] being the largest value and Array[ArrayLength-1] the smallest:

ARRAY SORT TEST

0,19.00000000001345

1,18.99999999999125

2,17.00000000000035

3,13.99999999998069

4,13.00000000001855

5,9.000000000014552

6,7.000000000001449

7,6.000000000017102

8,5.999999999994897

9,5.999999999994897

10,0.0

ArrayMaximum = 0

ArrayMinimum = 10

Array Sorted in Descending Order. Array[0] = 19.00000000001345

This result (at least for me) suggests that the sorting of largest to smallest is in Descending order.

Does anyone have a view on this?

Documentation on MQL5: Array Functions / ArraySort
• www.mql5.com
"The indicator analyzes data for the last month and draws all candlesticks with small" "to define such candlesticks. The candlesticks having the volumes comprising the first InpSmallVolume" "per cent of the array are considered small. The candlesticks having the tick volumes comprising ...
25233

90

Stanislav Korotky:

Solved!

If the Array is SetAsSeries, the ArraySort() function effectively sorts it in the opposite direction.

I suppose this is what the following line in the documentation means:

An array is always sorted in the ascending order irrespective of the AS_SERIES flag value.