Download MetaTrader 5

what's wrong with this array initialization?

To add comments, please log in or register
Richard
79
Richard  

it is declared global

int tflist[];

it is initialized in OnInit

tflist[8]={PERIOD_M1,PERIOD_M5,PERIOD_M10,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1};

it generates this error: '{' - expression expected. What am I doing wrong?

whroeder1
14781
whroeder1  
int tflist[8]={PERIOD_M1,PERIOD_M5,PERIOD_M10,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1};
// or let compiler count
int tflist[]={PERIOD_M1,PERIOD_M5,PERIOD_M10,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1};
Richard
79
Richard  
WHRoeder:
int tflist[8]={PERIOD_M1,PERIOD_M5,PERIOD_M10,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1};
// or let compiler count
int tflist[]={PERIOD_M1,PERIOD_M5,PERIOD_M10,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1};

both those options generated errors. by both declaring and initializing as a global, the problem was solved; it also worked when declared and initialized in OnCalculate. naturally, it would not work at all when declared and initialized in OnInit. could not declare in global and initialize in OnInit.
whroeder1
14781
whroeder1  
rwbta: by both declaring and initializing as a global, the problem was solved;
Isn't that what I posted?
Alain Verleyen
Moderator
31193
Alain Verleyen  
rwbta:

both those options generated errors. by both declaring and initializing as a global, the problem was solved; it also worked when declared and initialized in OnCalculate. naturally, it would not work at all when declared and initialized in OnInit. could not declare in global and initialize in OnInit.
You can declare it as global, and initialize in OnInit but not with the same syntax, you have to initialize an item at a time.
To add comments, please log in or register