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
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());
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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