MQ4, array problem, error: constant expression required

 

Please help some experienced coder.

After compiling get error constant expression required.

Problem is in array, strenghts is in pips. My idea is to get stongest and weakest pairs.

Code:

                int num_array1[8] ={EURstrenght,USDstrenght,AUDstrenght,NZDstrenght,CADstrenght,GBPstrenght,CHFstrenght,JPYstrenght};

                int    maxval=ArrayMaximum(num_array1);

int    minval=ArrayMinimum(num_array1);

int    max=num_array1[maxval];

                int    min=num_array1[minval];

 

Get errors EURstrenght - constant expression required

                USDstrenght - constant expression required.... etc

 

1) Please use the SRC-button if you post code (the SRC-icon of the top line of the online editor).

2) I guess (you don't post the whole code), that EURstrenght are valiables. You cant declare array using variables - you need to do that after that!

 
int num_array1[8] ={EURstrenght,USDstrenght,AUDstrenght,NZDstrenght,CADstrenght,GBPstrenght,CHFstrenght,JPYstrenght};
That is only valid if EURstrength is a constant. You have to set the array elements specifically
int num_array1[8];
num_array1[0] =EURstrenght;
num_array1[1] =USDstrenght;
:
 
That´s it!  There is no error after this correction. Thank you for help.
 
whroeder1:
int num_array1[8] ={EURstrenght,USDstrenght,AUDstrenght,NZDstrenght,CADstrenght,GBPstrenght,CHFstrenght,JPYstrenght};
That is only valid if EURstrength is a constant. You have to set the array elements specifically
int num_array1[8];
num_array1[0] =EURstrenght;
num_array1[1] =USDstrenght;
:

Thank you for this post!!!!!!! You just made my Array!!!!

 

Have to thank you too! Made me solve the problem quickly.

While the genuine error message "constant expression required" wasn't very helpful for me. As declaring the array elements "const" didn't help anything.

Great to have access to a forum like this ♥

 
William Roeder #:
int num_array1[8] ={EURstrenght,USDstrenght,AUDstrenght,NZDstrenght,CADstrenght,GBPstrenght,CHFstrenght,JPYstrenght};
That is only valid if EURstrength is a constant. You have to set the array elements specifically
int num_array1[8];
num_array1[0] =EURstrenght;
num_array1[1] =USDstrenght;
:
This is correct and awesome. However, note that this can't be done on a global scope. It has to be inside a function or the predefined functions for it to work successfully. 
Thought you should know that. Great solution. 
Reason: