MQL5 : Can we do late initialisation of array?

 

i want to do


   

ENUM_TIMEFRAMES xTF;
// some logic to set xTF 

 bool listOfIsNewCandle[6] ;



     if(someBoolCondition)

         {

            if(xTF == PERIOD_M1)

               listOfIsNewCandle = {isNewCandle_6min,isNewCandle_5min,isNewCandle_4min,isNewCandle_3min,isNewCandle_2min,false};

            if( xTF  == PERIOD_M2)

                listOfIsNewCandle = {isNewCandle_6min,isNewCandle_5min,isNewCandle_4min,isNewCandle_3min,false,false};

        }


But i get error

   

   'listOfIsNewCandle' - invalid array access   



Is it not possible to do late initialization of array like i am trying to do above?



I feel if i initialise every array index seperately its too verbose. So i wanted to code it like above.



 

Not possible. Create static array with same size inside the condition and do arraycopy e.g:

bool listOfIsNewCandle_Temp[6] ={isNewCandle_6min,isNewCandle_5min,isNewCandle_4min,isNewCandle_3min,isNewCandle_2min,false};
ArrayCopy(listOfIsNewCandle,listOfIsNewCandle_Temp,0,WHOLE_ARRAY);
 
Sardion Maranatha #:

Not possible. Create static array with same size inside the condition and do arraycopy e.g:

cool. thanks
 
Sardion Maranatha #: Not possible.
Of course, it's possible. Pass the array by reference. Do whatever you want with it. You can't return an array.
 
William Roeder #:
Of course, it's possible. Pass the array by reference. Do whatever you want with it. You can't return an array.
what's the initialized value of element when static array of bool with size of any natural number is declared?
 
Sardion Maranatha #: what's the initialized value of element when static array of bool with size of any natural number is declared?

There isn't any; you have random garbage, thus mostly true (false equals zero).

 
William Roeder #: Of course, it's possible. Pass the array by reference. Do whatever you want with it. You can't return an array.

Not possible to use the brackets except where declared and only with a constant.

Your original code (now modified) was trying to return and array from a function.

Reason: