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
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); }
I wonder why to add documentations for functions that aren't implemented yet 🤔
its like a whitepaper , or a roadmap . Invest while its early
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
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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