In MQL4, I could use the following function to print values from a two-dimensional array:
string Arr2ToString(double& arr[][], string dlm = ",", int digits = 2) {
string res = "";
int i, j;
for (i = 0; i < ArrayRange(arr, 0); i++) {
res += "[";
for (j = 0; j < ArrayRange(arr, 1); j++) {
res += StringFormat("%g%s", NormalizeDouble(arr[i][j], digits), dlm);
}
res = StringSubstr(res, 0, StringLen(res) - StringLen(dlm));
res += "]" + dlm;
}
res = StringSubstr(res, 0, StringLen(res) - StringLen(dlm));
return res;
}
However in MQL5 (version 5.00, build 1966), above function no longer works and it errors with:
'[' - invalid index value Array.mqh
in the first line when arr[][]
is passed.
I've checked and MQL5 no longer allows passing an array with no dimension sizes.
When passing multidimensional arrays to a function, dimension sizes (except for the first one) should be specified:
double var[][3][3]; void Func(double &arg[][3][3]){ // ... }
Source: MQL5 PROGRAMMING BASICS: ARRAYS.
This doesn't make sense.
Assuming I don't know the size of my array (as I want to re-use this function for multiple array types, and defining dozens of separate functions for each size is ridiculous), how it is possible now to print values from a multidimensional array storing double values (such as two-dimensional array as example)?
ArrayPrint()
function mql5.com/en/docs/array/arrayprint – TheLastStarkArrayPrint()
supports two-dimensional arrays? From the docs, it isn't clear. – kenorb