How to use 2d / 3d array for CopyBuffer

 
double Buffer[][], handle[][];
 if(CopyBuffer(handle[][],0,0,1,Buffer)==-1) Print("Failed to Copybuffer ", GetLastError());

If i have 2d or 3d array how do i copy buffer to it

Note : above code wont compile, its for reference what i am trying to do

 
Arpit T:

If i have 2d or 3d array how do i copy buffer to it

Note : above code wont compile, its for reference what i am trying to do

Place the cursor on CopyBuffer, press F1 and read the doc. There can get what this function provides and requires - anything else has to be coded bay yourself.
 
Arpit T:

If i have 2d or 3d array how do i copy buffer to it

Note : above code wont compile, its for reference what i am trying to do

Exactly as Carl said.. follow the documentation and write it how you want.

In this case you need to pass a single dimension array to the CopyBuffer() function

For example:

      double vectorRow[] = {};
      int     indicator_handle = 0; //example  
      if(CopyBuffer(indicator_handle,0,0,1,vectorRow)==-1) Print("Failed to Copybuffer ", GetLastError());

If you later want to use multi-dimension arrays you need to define the supporting dimensions - 4 dimensions are the limit in MQL5. Examples below:

   double Buffer2d[][2], handle2d[][2];
   double Buffer3d[][2][3], handle3d[][2][3];
   double Buffer4d[][2][3][4], handle4d[][2][3][4];      

You would need to write your own code to copy the values from the single dimension vector across to the multi-dimension arrays as you want, I don't think the ArrayCopy function could do it.

 

PS - on 2nd thoughts, you could ditch the multi-dimension approach and achieve what you want with 2 single dimension arrays. If necessary keep them together in a structure or object. You could write methods to ensure they are always sized the same, and also develop any other common operations as methods -see this simple example.

The benefit is you can use all the standard Array functions with ease, and also access CopyBuffer() directly.

   struct twoArrays
     {
      double         Buffer1d[], handle1d[];

      void           resizeBoth(int size)
        {
         ArrayResize(Buffer1d, size);
         ArrayResize(handle1d, size);
        }
        
     };

   twoArrays   twoArraysInStruc;

   twoArraysInStruc.resizeBoth(9);
   
   if(CopyBuffer(indicator_handle,0,0,1, twoArraysInStruc.Buffer1d) == -1)
      Print("Failed to Copybuffer ", GetLastError());
 
R4tna C #:

PS - on 2nd thoughts, you could ditch the multi-dimension approach and achieve what you want with 2 single dimension arrays. If necessary keep them together in a structure or object. You could write methods to ensure they are always sized the same, and also develop any other common operations as methods -see this simple example.

The benefit is you can use all the standard Array functions with ease, and also access CopyBuffer() directly.

Is it possible put an array as handle (and not a variable)?

Example: CopyBuffer(array[ ], buffer, ….) 
 
Milko Vivaldi #:
Is it possible put an array as handle (and not a variable)?

Example: CopyBuffer(array[ ], buffer, ….) 
No.