Sorting

 

As I know there is no sorting function in the mql4.

Can anybody help with a sorting code if any available?

I need a list of numbers to be sorted in descending order.

Thank you.

 
Brygada:

As I know there is no sorting function in the mql4.

Can anybody help with a sorting code if any available?

I need a list of numbers to be sorted in descending order.

Thank you.

ArraySort()

 
gordon:

ArraySort()

Very nice.

I never used it.

Thanks a lot.

 

I am not good at arrays.

When I run

-------------------------

double X=1.1;

double Hello[1] = {1.1};

---------------------

it works but

when

-------------------------------

double X=1.1;

double Hello[1] = {X};

---------------------------

it gives errors.

I do really need to use variables.

Is there any way to solve this problem.?

 

why {X} instead of X ??

double Hello[1] = X;

 
Brygada:

double X=1.1;

double Hello[1] = {X};

Interesting. It really doesn't seem to work. I think that this is the first bona fide language bug I've seen reported on this forum in the 12 months I've been hanging around. I assume that it "ought" to work; it does in C.


However, it doesn't work in the MQL5 compiler either (build 226), though that gives an explicit error message saying that constants are required for array initialisation.


I don't think you have an alternative to populating the array manually, as Matutin is suggesting.

 
Matutin:

why {X} instead of X ??

double Hello[1] = X;

I put

----------------------

double X=1.1;

double Hello[1] = X;

---------------------------

and it gives me error:

'X'-unexpected token

 

jjc wrote >>

...though that gives an explicit error message saying that constants are required for array initialization.

Same in MQL4 -> "All arrays, including those declared in the local scope, can be initialized with constants only" (MQL4 Reference -> Basics -> Variables -> Initialization of variables).


Edit: BTW, this has to do with the fact that arrays in MQL4 are static by default. Global variables (which are also static by default) and static variables have to be initialized with a constant as well...

 

a[1] = {x}

can only be used if x is a constant (or a #define)

if x i not a constant you must initialize it with a[1]=x; normally in init()

extern type var = 123;

var is not a constant. Neither is Point;

 
WHRoeder:

can only be used if x is a constant (or a #define)

if x i not a constant you must initialize it with a[1]=x; normally in init()

extern type var = 123;

var is not a constant. Neither is Point;


 

The problem is solved.

I did

double A = 1.1;

double B[1];

B[0] = A;


I did not know that only constants must be in array cells.

Thanks everybody for your quick and kind help.

Reason: