Download MetaTrader 5

Compilation error "constant value expected"

To add comments, please log in or register
Joaquin Poudereux
Joaquin Poudereux 2012.08.01 21:26 

Hi all,

Although this error is clairly explanatory by itself, i still can´t find a solution to a problem I´ve found.

I want to have an  Array of structs, visible to all the EA. Being global or static is not important, I only want to be visible by all components of the EA.

I want to initialize the values of the Array with extern variables, so to be able to backtest and optimize changing these values.

How could I achieve it?

The code is something like this:

(It is written by hand, so it is prone to errors):

extern string symbol1 = "EURUSD";
extern int pipsSL1 = 15;
extern int pipsTP2 = 50;

extern string symbol2 = "GBPUSD";
extern int pipsSL2 = 25;
extern int pipsTP2 = 120;

struct symbolProps {
   string mysymb;
   int mySLpips;
   int myTPpips;

symbolProps ArraySymbols[12] = 
{ { symbol1 , pipsSL1 , pipsTP1 } ,
  { symbol2 , pipsSL2 , pipsTP2 }
// Other symbols
Joaquin Poudereux
Joaquin Poudereux 2012.08.01 23:24  

Sorry for adding this comment in the General Forum. 

I imagine this would best fit in the Expert Advisors and Programming Forum. I've looked for the option of moving this comment to that Forum, but I couldn't find it.

Maybe the reasons is that only administrators can move posts to other threads?


Anyway, thanks for all you who read this. I hope someone knows how to solve it the sooner the better. I must continue my developing for the ATC!!


Joaquin Poudereux
Joaquin Poudereux 2012.08.06 20:10  

Just in case this post helps someone.
I had a bug in my code. I intended to have input variables, what used to be "extern" variables in mql4, and now are called "input" variables.
The code worked, but not the way I liked.
I just added the code for all the input variables. And then, inside the OnInit() function, I added the initialization, but not like I was trying -I wanted not to write too much code-, but in this way

ArraySymbols[0].mySLpips = pipsSL1;

And so and so... It just worked for me.
To add comments, please log in or register