Download MetaTrader 5

FileWriteArray

To add comments, please log in or register
Do you have questions on how to turn your idea into reality? Ask them on the Forum!
Stephen Njuki
5179
Stephen Njuki 2011.07.09 18:00 

I have just reported this to service desk but I was wondering if anybody else having same problem.

I cannot create dat or csv files from an array even though the array has data.

Stephen Njuki
5179
Stephen Njuki 2011.07.09 22:14  

Hey guys any response from Metaquotes here will be helpful. 

This code is not working

      string m_file = "-Weights-";
      string BufferWeights[8][8];//Static array declared globally but shown here for clarity
      int handle = FileOpen(m_file+".dat",FILE_READ|FILE_WRITE|FILE_BIN);
      if(handle!=INVALID_HANDLE)
      {
         FileWriteArray(handle,BufferWeights,0,WHOLE_ARRAY);
         FileClose(handle);
      }
      if(handle==INVALID_HANDLE)
      {
         printf(__FUNCTION__+": error writing weights to file");
      }

I have also tried this but I get same results

       int handle = FileOpen(m_file+".dat",FILE_SHARE_WRITE|FILE_WRITE|FILE_BIN);


      int handle = FileOpen(m_file+".dat",FILE_SHARE_WRITE|FILE_READ|FILE_WRITE|FILE_BIN);


Please help

Ilyas
1205
Ilyas 2011.07.11 16:13  
Strings cannot be written to a binary file. Use FILE_TXT instead of FILE_BIN to open a text file.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
  • www.mql5.com
Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags - Documentation on MQL5
Stephen Njuki
5179
Stephen Njuki 2011.07.12 10:36  
mql5:
Strings cannot be written to a binary file. Use FILE_TXT instead of FILE_BIN to open a text file.

Спасибо Мистер MQL5
Stephen Njuki
5179
Stephen Njuki 2011.12.09 12:39  
mql5:
Strings cannot be written to a binary file. Use FILE_TXT instead of FILE_BIN to open a text file.

 Can someone please help me with reading array files. This code now keeps throwing up error 5004

 

      
      //-----------------------------------------------------------------------------------------------------
      //All these options for the file path of the read file, "m_weights_file", throw up errors 5004 or 5002
      //-----------------------------------------------------------------------------------------------------

      m_weights_file = /*TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL5\\"+*/"SOMWeights " + IntegerToString(ArraySize(GridWeights))+".dat";
      //m_weights_file="D:\Program Files\MetaTrader 5\MQL5\Files\SOMWeights 20736.dat";
      int handle = FileOpen(m_weights_file,FILE_READ|FILE_TXT|FILE_ANSI);
      
      if(handle!=INVALID_HANDLE)
      {
         printf(__FUNCTION__+" Read array!! ");
         FileReadArray(handle,GridWeights,0,WHOLE_ARRAY);
         FileClose(handle);
      }
      if(handle==INVALID_HANDLE)
      {  
         printf(__FUNCTION__+" unable to read array @ "+m_weights_file+" !!... "+string(GetLastError()));// this is the error I keep getting...
      }

 

 

Any help on resolving this will be highly appreciated. The .dat file stores strings written from an array. 

Stephen Njuki
5179
Stephen Njuki 2011.12.09 13:29  
ssn:

 Can someone please help me with reading array files. This code now keeps throwing up error 5004

 

 

 

Any help on resolving this will be highly appreciated. The .dat file stores strings written from an array. 

The tester file property is also not workin...


#property tester_file "SOMWeights 20736.dat"

      
      //--- 

      m_weights_file="SOMWeights 20736";
      int handle = FileOpen(m_weights_file,FILE_READ|FILE_TXT|FILE_ANSI);

      //same code as above...

  I still get error 5004 despite the fact that the file is present in the MQL5\files directory.

Read Array Error 

Ilyas
1205
Ilyas 2011.12.09 16:18  
m_weights_file="SOMWeights 20736";
Where extension?
Stephen Njuki
5179
Stephen Njuki 2011.12.09 17:01  
Hey I thought this works like a custom indicator but I added the extension and it finally worked. Thanks a lot man.... would have bought you a vodka if we were in the same town. Thanks.
Step on New Rails: Custom Indicators in MQL5
  • 2009.11.23
  • Андрей
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
To add comments, please log in or register