>>> can you help me please ?
I can not find the equivalent in MQL5 doing sort for ((( string values ))) .... this my code in MQL4 and ArraySort works OK in string values
https://www.mql5.com/en/docs/array/arraysort
It can not sort based on string according to the docs.
Maybe this https://www.mql5.com/en/articles/1334 can help you to give Arrays more functionality found in other programming languages.
- www.mql5.com
>>> can you help me please ?
I can not find the equivalent in MQL5 doing sort for ((( string values ))) .... this my code in MQL4 and ArraySort works OK in string values
I solve My Problem by working with ArrayString.mqh file
#include <Arrays\ArrayString.mqh> // put this line at the begin of code after #property lines void OnTick() { CArrayString *array=new CArrayString; // put this line at the begin of OnTick() or at the begin of OnStart() . . . string x[]; for(int i=0;i<PositionsTotal();i++) { PositionGetTicket(i); array.Insert(PositionGetString(POSITION_SYMBOL),i); } array.Sort(0); for(int i=0;i<PositionsTotal();i++) { x[i]=array.At(i); }
I solve My Problem by working with ArrayString.mqh file
Glad you solved your problem and posted the solution. Thanks!
https://www.mql5.com/en/docs/array/arraysort
It can not sort based on string according to the docs.
Maybe this https://www.mql5.com/en/articles/1334 can help you to give Arrays more functionality found in other programming languages.
Thanks for your response ... I found the solution ... and i put it in comments
I solve My Problem by working with ArrayString.mqh file
Hi, just a couple of tips when working with the standard library collections... See comments in code.
void OnStart() { //CArrayString *array=new CArrayString; // put this line at the begin of OnTick() or at the begin of OnStart() CArrayString array; //Better to statically instantiate so you don't have to remember to delete. string x[]; //You already have a string array object... no point in having two... but leaving it here for demonstration for(int i=0;i<PositionsTotal();i++) { PositionGetTicket(i); //array.Insert(PositionGetString(POSITION_SYMBOL),i); //Add is safer and quicker. Only use insert when you have to specify the index array.Add(PositionGetString(POSITION_SYMBOL)); } //array.Sort(0); array.Sort(); ArrayResize(x,array.Total()); //for(int i=0;i<PositionsTotal();i++) for(int i=0;i<array.Total();i++) { //x[i]=array.At(i);// use the overloaded operator instead
x[i]=array[i]; } }
I solve My Problem by working with ArrayString.mqh file
There are a lot of ways to code inefficiently. If you are just happy it's working no problem for me, but putting all these strings in an array to sort it, is really time consuming.
May I ask you why you need to sort symbols used on every position ?
I solve My Problem by working with ArrayString.mqh file
Thanks, this helped me a ton!
Hi, just a couple of tips when working with the standard library collections... See comments in code.
These tips worked like gold for me, thank you!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
>>> can you help me please ?
I can not find the equivalent in MQL5 doing sort for ((( string values ))) .... this my code in MQL4 and ArraySort works OK in string values