You just write the array of pointers :
FileWriteArray(_handle,_arrays.N,0,WHOLE_ARRAY);and you are expecting it will write all values, why ?
You just write the array of pointers :
and you are expecting it will write all values, why ?I do not think that it is possible to use FileWriteArray() and FileReadArray() to work with multidimensional arrays in a single file (especially the read part). You may try to save and load the information similar to the way the standard library does it with string and arrays. First, it writes/loads the size of the data that need to be written/loaded, then starts writing/loading the actual items one by one until the size of the data is reached.
From Arrays\ArrayDouble.mqh:
//+------------------------------------------------------------------+ //| Writing array to file | //+------------------------------------------------------------------+ bool CArrayDouble::Save(const int file_handle) { int i=0; //--- check if(!CArray::Save(file_handle)) return(false); //--- write array length if(FileWriteInteger(file_handle,m_data_total,INT_VALUE)!=INT_VALUE) return(false); //--- write array for(i=0;i<m_data_total;i++) if(FileWriteDouble(file_handle,m_data[i])!=sizeof(double)) break; //--- result return(i==m_data_total); } //+------------------------------------------------------------------+ //| Reading array from file | //+------------------------------------------------------------------+ bool CArrayDouble::Load(const int file_handle) { int i=0,num; //--- check if(!CArray::Load(file_handle)) return(false); //--- read array length num=FileReadInteger(file_handle,INT_VALUE); //--- read array Clear(); if(num!=0) { if(!Reserve(num)) return(false); for(i=0;i<num;i++) { m_data[i]=FileReadDouble(file_handle); m_data_total++; if(FileIsEnding(file_handle)) break; } } m_sort_mode=-1; //--- result return(m_data_total==num); }
I think an easier alternative would be to use CArrayDouble to store your arrays/values. For nested arrays, you may store each CArrayDouble instance on CArrayObj. So it should be CArrayDouble for the deepest levels, and CArrayObj for the rest. After this, you can call the Save() and Load() functions of the class, without having to write a custom solution. You call the save/load function of the main object instance that stores all the others, and the saving and loading will be done recursively.
I do not think that it is possible to use FileWriteArray() and FileReadArray() to work with multidimensional arrays in a single file (especially the read part). You may try to save and load the information similar to the way the standard library does it with string and arrays. First, it writes/loads the size of the data that need to be written/loaded, then starts writing/loading the actual items one by one until the size of the data is reached.
From Arrays\ArrayDouble.mqh:
I think an easier alternative would be to use CArrayDouble to store your arrays/values. For nested arrays, you may store each CArrayDouble instance on CArrayObj. So it should be CArrayDouble for the deepest levels, and CArrayObj for the rest. After this, you can call the Save() and Load() functions of the class, without having to write a custom solution. You call the save/load function of the main object instance that stores all the others, and the saving and loading will be done recursively.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am using Arrays.mqh listing to write nested arrays to .bin file with _writer.mq5. I think it is working because when compared written nested arrays that are structs, the bin file that is created is not zero bytes in size.
Now the problem am facing is in trying to read the created bin file. _read.mq5 indicates all the array values as 0.0 which is not what was written.
So my question is how does one read a bin file that has nested arrays? Here are the listings.
Arrays.mqh
_write.mq5,
and finally _read.mq5