MQL5 Question: unable to initialise a 2 dimensional array using existing array variables

 

Hi

Below is the code (for Script) i am trying to compile but i get error. I am not sure why i cant get this syntax to work.

enum SBP
  {
   SS = 0,

   MM = 1,
   
   WW = 2
  };
void OnStart()
  {
        double aa[5] = {1,2,3,4,5 };
        double bb[5] = {6,7,8,9,10 };
         double cc[5] = {11,12,13,14,15};
      
        double dd[3][5] = {aa, bb, cc};
        Print(" dd[WW][SS]  = ",dd[WW][SS]);
  }



Error is shown below:

'aa' - invalid array access     
'bb' - invalid array access     
'cc' - invalid array access     


 

It is simply not the way you can deal with array in MQL5.

For what you want you should use matrices and vectors. See here https://www.mql5.com/en/docs/matrix
and study the examples there.

Documentation on MQL5: Matrix and Vector Methods
Documentation on MQL5: Matrix and Vector Methods
  • www.mql5.com
A matrix is a two-dimensional array of double, float, or complex numbers. A vector is a one-dimensional array of double, float, or complex numbers...
 
Varun Maithani:

Below is the code (for Script) i am trying to compile but i get error. I am not sure why i cant get this syntax to work.

Error is shown below:

You can initialize N-dimensional arrays directly:

  double dd[3][5] =
  {
    {1,2,3,4,5},
    {6,7,8,9,10},
    {11,12,13,14,15}
  };
 
Stanislav Korotky #:

You can initialize N-dimensional arrays directly:

Thanks i will use that way then