Mql5 error when use vector::Sort. It is a bug !!!

 

Hello guys, 

I have a problem when try to use example for vector::Sort at https://www.mql5.com/en/docs/matrix/matrix_manipulations/matrix_sort

when I compile it said error that:

'Sort' is not a member of 'vector' type

I try some another ways but still don't know the way to use Sort method

Can you give me some correct example for vector::Sort? (also for matrix::Sort)

I use MetaTrader 5 build 4153, updated at 22 Jan 2024

Thank you,

Momoinu


Documentation on MQL5: Matrix and Vector Methods / Manipulations / Sort
Documentation on MQL5: Matrix and Vector Methods / Manipulations / Sort
  • www.mql5.com
Sort - Manipulations - Matrix and Vector Methods - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Huy Nguyễn:

Hello guys, 

I have a problem when try to use example for vector::Sort at https://www.mql5.com/en/docs/matrix/matrix_manipulations/matrix_sort

when I compile it said error that:

I try some another ways but still don't know the way to use Sort method

Can you give me some correct example for vector::Sort? (also for matrix::Sort)

I use MetaTrader 5 build 4153, updated at 22 Jan 2024

Thank you,

Momoinu



Documentation gives an example, doesn't that work?

Please always provide compilable code to reproduce the issue you are reporting.
 
Dominik Egert #:
Documentation gives an example, doesn't that work?

Please always provide compilable code to reproduce the issue you are reporting.

Hello sir,

I try to use code from Documentation but it not work, I also attached an image that show my code and the error in MetaEditor UI.

Here is detail code:

//+------------------------------------------------------------------+
//|                                                       TestHi.mq5 |
//|                                                          Momoinu |
//|                                         Momoinu@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Momoinu"
#property link      "Momoinu@gmail.com"
#property version   "1.00"

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Sort function                                                    |
//+------------------------------------------------------------------+
int MyDoubleComparator(double x1,double x2,int sort_mode=0)
  {
   int res=x1<x2 ? -1 : (x1>x2 ? 1 : 0);
   return(sort_mode==0 ? res : -res);
  }
//+------------------------------------------------------------------+
//| Script start function                                            |
//+------------------------------------------------------------------+
void OnStart()
  {
   //--- fill the vector
   vector v(100);
   //--- sort ascending
   v.Sort(MyDoubleComparator);   // an additional parameter with the default value '0' is used here
   Print(v);
   // sort descending
   v.Sort(MyDoubleComparator,1); // here the additional parameter '1' is explicitly specified by the user
   Print(v);
  }

can you try it?

Thank you

 

I think it is not implemented yet 

try this :

void init_and_sort(vector &to_initialize,double &values[],ENUM_SORT_MODE mode){
ArraySort(values);
if(mode==SORT_DESCENDING){ArrayReverse(values,0,ArraySize(values));}
for(int i=0;i<ArraySize(values);i++){to_initialize[i]=values[i];}
}
//+------------------------------------------------------------------+
//| Script start function                                            |
//+------------------------------------------------------------------+
int OnInit()
  {
  double the_values[]={0.1,0.22,0.03,1.1,-0.4};
  vector v(ArraySize(the_values),init_and_sort,the_values,SORT_DESCENDING);
  Print(v);
  //--- fill the vector
   /*
   vector v(100);
   
   //--- sort ascending
   v.Sort(MyDoubleComparator);   // an additional parameter with the default value '0' is used here
   Print(v);
   // sort descending
   v.Sort(MyDoubleComparator,1); // here the additional parameter '1' is explicitly specified by the user
   Print(v);
   */
  return(INIT_SUCCEEDED);
  }
 
Lorentzos Roussos #:

I think it is not implemented yet 

try this :

Hello sir,

This work for me, thank you :D

Also I thought that I can ask ChatGPT to dev the Sort func for vector, that I forgot before =)))

 
I wonder why to add documentations for functions that aren't implemented yet 🤔 
 
amrali #:
I wonder why to add documentations for functions that aren't implemented yet 🤔 

its like a whitepaper , or a roadmap . Invest while its early

Huy Nguyễn #:

Hello sir,

This work for me, thank you :D

Also I thought that I can ask ChatGPT to dev the Sort func for vector, that I forgot before =)))

you are welcome 

 
amrali #:
I wonder why to add documentations for functions that aren't implemented yet 🤔 

me too, that make me feel surprise then I forgot we can easy develop this, instead of try to understand