Download MetaTrader 5

Initializing an array with extern variables not possible in a script? Compiling error..

To add comments, please log in or register
Examine the Top MetaTrader 5 signals. Choose the best one and subscribe to it!
mar
1146
mar 2013.12.26 17:40 

Hi coders,

I wanted to create a script which contains user-defined colors. But there is always a compiling error. I think it is not possible to initialize an array with user-defined variables. But how can I solve this problem?

When I initialize the array directly with the colors, there is no problem...

#property show_inputs

extern color   MN1_col = White;
extern color   W1_col = Red;
extern color   D1_col = Yellow;
extern color   H4_col = Lime;
extern color   H1_col = Aqua;
extern color   M30_col = Purple;
extern color   M15_col = Purple;
extern color   M5_col = Purple;
extern color   M1_col = Purple;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int TF[]       = {PERIOD_MN1, PERIOD_W1, PERIOD_D1, PERIOD_H4, PERIOD_H1, PERIOD_M30, PERIOD_M15, PERIOD_M5, PERIOD_M1};
   color Colors[] = {MN1_col, W1_col, D1_col, H4_col, H1_col, M30_col, M15_col, M5_col, M1_col};


Can anyone help?

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.12.26 17:50  
mar:

Hi coders,

I wanted to create a script which contains user-defined colors. But there is always a compiling error. I think it is not possible to initialize an array with user-defined variables. But how can I solve this problem?

When I initialize the array directly with the colors, there is no problem...


Can anyone help?

You can only initialise an array with constants . . .

Try this instead:

#property show_inputs

extern color   MN1_col = White;
extern color   W1_col = Red;
extern color   D1_col = Yellow;
extern color   H4_col = Lime;
extern color   H1_col = Aqua;
extern color   M30_col = Purple;
extern color   M15_col = Purple;
extern color   M5_col = Purple;
extern color   M1_col = Purple;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int TF[]       = {PERIOD_MN1, PERIOD_W1, PERIOD_D1, PERIOD_H4, PERIOD_H1, PERIOD_M30, PERIOD_M15, PERIOD_M5, PERIOD_M1};
   color Colors[9];
   
   Colors[0] = MN1_col; Colors[1] = W1_col; Colors[2] = D1_col; Colors[3] = H4_col; Colors[4] = H1_col; 
   Colors[5] = M30_col; Colors[6] = M15_col; Colors[7] = M5_col; Colors[8] = M1_col;
mar
1146
mar 2013.12.26 19:28  
Thanks, Raptor... It works perfect now!
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.12.26 20:35  
mar:
Thanks, Raptor... It works perfect now!
To add comments, please log in or register