2d array sort

 

Hi group, i have a question :)

i am trying to find a workaround on how to sort a 2 dimensional array in mql5 however until now, i can't make it.

there are 2 posts i can find on this forum about the subject:

https://www.mql5.com/en/forum/1214

https://www.mql5.com/en/forum/3660

none of them actually helped me.

in mql4 this was a simple task just using arraysort, however on mql5 this is not possible.

here is an example of what i am trying to do. example array:

[4]["hello"]
[1]["goodbye"]
[6]["sayonara"]
[2]["hola"]

output of arraysort with mql4, in mode asc:

[1]["goodbye"]
[2]["hola"]
[4]["hello"]
[6]["sayonara"]

can anyone point me to an example or some code on how to achieve this on mql5 ?

thanks, any help will be appreciated.

 
oxarbitrage:

Hi group, i have a question :)

i am trying to find a workaround on how to sort a 2 dimensional array in mql5 however until now, i can't make it.

there are 2 posts i can find on this forum about the subject:

https://www.mql5.com/en/forum/1214

https://www.mql5.com/en/forum/3660

none of them actually helped me.

in mql4 this was a simple task just using arraysort, however on mql5 this is not possible.

here is an example of what i am trying to do. example array:

[4]["hello"]
[1]["goodbye"]
[6]["sayonara"]
[2]["hola"]

output of arraysort with mql4, in mode asc:

[1]["goodbye"]
[2]["hola"]
[4]["hello"]
[6]["sayonara"]

can anyone point me to an example or some code on how to achieve this on mql5 ?

thanks, any help will be appreciated.

 

As you asked for a workaround, have you tried to join the two fields like "00001 goodbye" and work as one dimension array of string? 

 

 
Jin:

As you asked for a workaround, have you tried to join the two fields like "00001 goodbye" and work as one dimension array of string? 

 

Hi Jin, thank you for your answer, i am pretty sure your option can work. i stopped looking because i was actually needing the maximum and minimum value of the array only. so, instead of one 2d array i made 2 arrays like:

array1:

[4]
[1]
[6]
[2]

array2:

["hello"]
["goodbye"]
["sayonara"]
["hola"]

using ArrayMaximum() and ArrayMinimum() on array1 i can get the indexes for array2 for the max and min values of array1.

i appreciate your comment.

thanks.

oxarbitrage.

Documentation on MQL5: Array Functions / ArrayMaximum
  • www.mql5.com
Array Functions / ArrayMaximum - Documentation on MQL5