How to sort symbols (string) ?

 

Hi coders, I have an EA when I write an instruction such as :-

   Print(symbol);

The symbols with open orders will be printed out in the Expert tab. I noticed that at the moment any new order comes in or existing order is closed, the sequence of the symbols will be changed. I tried to use ArraySort to sort the symbols but seems the ArraySort function does not work for string, but only work for values.

Could you please provide me the coding steps how to sort the symbols automatically in MODE_ASCEND order ? Thank you.

 
Chin Min Wan:

Hi coders, I have an EA when I write an instruction such as :-

The symbols with open orders will be printed out in the Expert tab. I noticed that at the moment any new order comes in or existing order is closed, the sequence of the symbols will be changed. I tried to use ArraySort to sort the symbols but seems the ArraySort function does not work for string, but only work for values.

Could you please provide me the coding steps how to sort the symbols automatically in MODE_ASCEND order ? Thank you.

Maybe you want to try this library.


You will need to provide a comparison function, which you can realize easily with this:


 

Also you can use CArrayString:

#include <Arrays/ArrayString.mqh>
...
  {
   CArrayString arr = new CArray();
   const string s[]={"4","1","3","2"};
   arr.Insert(s[0], 0);
   arr.Insert(s[1], 1);
   arr.Insert(s[2], 2);
   arr.Insert(s[3], 3);
   arr.Sort(0);
   delete &arr;
...
  }