assigning external variables to an array

marksimmonds  

Hi, I'm sure this is a basic programming misunderstanding on my behalf -

I'm getting a 'constant expression required' error message when compiling. 

I simply want to create an array based on extern inputs to the program. I've tried putting the code globally and in a function but getting the same results. It seems to work if I simply assign the array values manually, but not when I try to use a variable.

 What I was trying to do was create a bool function to say yes or no to trading at a particular time, based on the inputs. I understand there are probably easier ways, but I want the 'on/off' per hour ability.  

 Any help appreciated. Thanks, Mark.

 

//+------------------------------------------------------------------+
//| Mark's Time to Trade Test
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
// -- Variables
//+------------------------------------------------------------------+
extern string Comments2 = "-------- Day of Week ----------";
extern int TradeSun = 1;
extern int TradeMon = 1;
extern int TradeTue = 1;
extern int TradeWed = 1;
extern int TradeThu = 1;
extern int TradeFri = 1;
extern int TradeSat = 1;
extern string Comments3 = "-------- Hours of Day ---------";
extern string Comments4 = "--- Enter 0 to turn off trading Hour ----";
extern int Hour0_1 = 1;
extern int Hour1_2 = 1;
extern int Hour2_3 = 1;
extern int Hour3_4 = 1;
extern int Hour4_5 = 1;
extern int Hour5_6 = 1;
extern int Hour6_7 = 1;
extern int Hour7_8 = 1;
extern int Hour8_9 = 1;
extern int Hour9_10 = 1;
extern int Hour10_11 = 1;
extern int Hour11_12 = 1;
extern int Hour12_13 = 1;
extern int Hour13_14 = 1;
extern int Hour14_15 = 1;
extern int Hour15_16 = 1;
extern int Hour16_17 = 1;
extern int Hour17_18 = 1;
extern int Hour18_19 = 1;
extern int Hour19_20 = 1;
extern int Hour20_21 = 1;
extern int Hour21_22 = 1;
extern int Hour22_23 = 1;
extern int Hour23_24 = 1;

//bool tradeThisDay[7] = {TradeSun,1,1,1,1,1,0};
//bool tradeThisHour[24] = {Hour0_1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

//+------------------------------------------------------------------+
// -- Functions
//+------------------------------------------------------------------+

bool TradeAtThisTime()
   {     
    bool tradeThisDay[7] = {TradeSun,1,1,1,1,1,0};
    bool tradeThisHour[24] = {Hour0_1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
         if (tradeThisDay[DayOfWeek()]==1 && tradeThisHour[Hour()]==1)
            {
            return(true);
            }
    return(false);
   }
      
//+------------------------------------------------------------------+     


int init() {    
   return(0);
}

//+------------------------------------------------------------------+

 

int deinit() {
   return(0);
}

//+------------------------------------------------------------------+

int start() {

   return(0);
}
Alain Verleyen  

You can't proceed this way. You have to assign value to your array one by one.

Your array is bool, your input parameters are int, not a good idea.

Alain Verleyen  
marksimmonds:

thanks i got it to work one-by-one, and thanks for the tip re book/ints.

Is there a technical reason why you cant add them in one, or just something peculiar to mql4?

It's how mql4 (and mql5) is designed.
Nico Aguinsky  

Can you explain how it is done??? i have the same problem

Reason: