I have need to declare an array that contains double data types, but I get the following error message:
'USDbefore1' - constant expression required
Not sure how I should go about it.
(Will something like "structs" solve the problem? - Obviously a question from a pure novice!)
Here is the code:
The problem is your declaration . . . declare it, then set the values.
Thanks for helping RaptorUK.
Could you elaborate a little on "declare it" please? Are you referring to the arrays or the variables?
When I declare them one by one like this it works, but I do not want to write 24 lines of code where 3 lines could do it.
Before1[0] = USDbefore1; Before1[1] = EURbefore1; etc.
As RaptorUK said, the problem is your declaration. An array may be initialized at declaration only by constants. See Initialization of Variables.
Just declare your array and then set each element (one by one) to the desired value. You might even be able to create a loop to set each element in the arrays, which would possibly save lines of code.
double USDbefore1 = iCustom(NULL,0,"CurrencySlopeStrengthNew",0,1); double USDbefore2 = iCustom(NULL,0,"CurrencySlopeStrengthNew",0,2);You can not declare variables globally and initialize them with non-constants. Either declare them globally and initialize them in OnTick() or move them into OnTick()
double Before1[8] = {USDbefore1,EURbefore1,GBPbefore1,CHFbefore1,JPYbefore1,AUDbefore1,CADbefore1,NZDbefore1};Same problem, non-contants
Declare the arrays and intitialize them with a constant like this before you use them to store variables.
double Before1[8]={0};
I used zero but you could also use the special constant NULL
double Before1[8]={NULL};
That declares the array and initializes it.
After that you then you can put whatever you want in it.
Thirteen:
. . . You might even be able to create a loop to set each element in the arrays, which would possibly save lines of code.
Code compiles but has not been tested.
// Declare arrays and initialize to zero double Before1[8] = {0}, Before2[8] = {0}, After[8] = {0}; // Set array elements to desired values for (int i = 0; i < 8; i++) { After[i] = iCustom(NULL,0,"CurrencySlopeStrengthNew",i,0); Before1[i] = iCustom(NULL,0,"CurrencySlopeStrengthNew",i,1); Before2[i] = iCustom(NULL,0,"CurrencySlopeStrengthNew",i,2); }
Thank you very much guys! You are really very generous in your advice and assistance. I have learned a lot from this.
Roeder and Thirteen - you were exceptionally helpful. Thanks a lot!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have need to declare an array that contains double data types, but I get the following error message:
'USDbefore1' - constant expression required
Not sure how I should go about it.
(Will something like "structs" solve the problem? - Obviously a question from a pure novice!)
Here is the code: