Sort multiple arrays

Back to topics list To post a new topic, please log in or register
avatar
5
sky90 2016.07.19 01:43
 

Hi, I have three arrays:

 

  • "Pair1"
  • "Pair2"
  • "Profit"

For example Pair1{EURUSD,GBPUSD}  / Pair2{AUDUSD,NZDUSD} / Profit{100,300}

These values are linked, so an output could be:

"Index 0: EURUSD-AUDUSD-100"

"Index 1: GBPUSD-NZDUSD-300".  

 Now I would sort a single array and then I would that other 2 arrays will remain linked to the sorted array.

So for example if I want to sort the third array "Profit" (desc) it will be {300,100}. Now pair1 and pair2 array should be {GBPUSD,EURUSD} and {NZDUSD,AUDUSD}. How can i do this in mql4?

Sorry for english, it's not my language. I hope it's enough clear.

Thanks for your help! 

avatar
872
eevviill 2016.07.19 13:08 #
 

2 ways

long buffers_index_copy[];
long buf_index_copy3[];
ArrayResize(buffers_index_copy,symols_chek_counter);
ArrayResize(buf_index_copy3,symols_chek_counter);
ArrayCopy(buffers_index_copy,volumes);
ArrayCopy(buf_index_copy3,volumes);
ArraySort(volumes,WHOLE_ARRAY,0,MODE_DESCEND);




for(int i=0;i<symols_chek_counter;i++)
{
if(volumes[i]==0) continue;
for(int bs=0;bs<symols_chek_counter;bs++)
{
if(volumes[i]==buffers_index_copy[bs])
{
...
buffers_index_copy[bs]=0;
break;
}
}
}

      

ArrayCopy(volumes,buf_index_copy3);

 

2)

 Asort[ 40, 2]

 Asort[ i, 0]=values

 Asort[ i, 1]=index in start arrays

avatar
5
sky90 2016.07.19 14:20 #
 
Thanks eevviill, can you insert some comments to explain what you did? I need to sort also string arrays so I can't use always ArraySort function
avatar
13006
WHRoeder 2016.07.19 21:19 #
 
Then you'd have write a specific sort, Array or not to array (Mike Tanton) - MQL4 forum - Page 2 #4
avatar
5
sky90 2016.07.20 01:23 #
 
WHRoeder:
Then you'd have write a specific sort, Array or not to array (Mike Tanton) - MQL4 forum - Page 2 #4

Thanks, do you mean to sort string arrays?

If someone could do an example in mql4 like I did with simple text in my post, I will really appreciate it

avatar
13006
WHRoeder 2016.07.20 16:20 #
 
The insertion sort I posted sorts any native type, and with a defined operator<() or a predicate any type. You would know this had you bothered to read the link provided.
avatar
5
sky90 2016.07.21 01:37 #
 
WHRoeder:
The insertion sort I posted sorts any native type, and with a defined operator<() or a predicate any type. You would know this had you bothered to read the link provided.

I read but I did not understand anything that's why I asked if it was possible a concrete example with the data that I put in the first post. In any case, thanks for the link.

You posted a mqh file with some functions that I don't understand, sorry. But I have to use "insertion_sort" function with which parameters?

 

If I have 5 string arrays and 5 double arrays, if I do this:

insertion_sort(MyStringArray,0,ArraySize(MyStringArray),MyFilterArray);

 I have an overload error.

Back to topics list  

To add comments, please log in or register