Error 5004 wirting csv

To add comments, please log in or register
Florian Riedrich
396
Florian Riedrich  

Hi,

I just want to write some data to a csv. But I cannot see my mistake

I get error 5004 over and over again. It creates the file, but it's size=0.

The Timer is set to 5 sec.

the "int start()"-function doesn't help either.


Thanks in advance


void OnTimer()
{

if (RunEA && IsTradeAllowed()) {

   int handle=FileOpen("test.csv",FILE_READ|FILE_WRITE|FILE_CSV,";");
   if(handle==INVALID_HANDLE){
      Print("Error opening file. Error code: ",GetLastError());
      return;
   }
   
   if (handle>1)
   {
      Print("File open");
      FileWrite(handle,"Symbol","Ask","Bid"); //Name column headers
      FileSeek(handle, 0, SEEK_END); // go to end of file
      //Record Indicator values
      
      FileWrite(handle,
      Symbol(),
      Ask,
      Bid);      
      
      FileClose(handle); //Close file
   }
}
}
Magruder Trading Group, Inc.
167
Chad Magruder  
void OnTimer()
{

if (RunEA && IsTradeAllowed()) {

   int handle=FileOpen("test.csv",FILE_READ|FILE_WRITE|FILE_CSV,";");
   if(handle==INVALID_HANDLE){
      Print("Error opening file. Error code: ",GetLastError());
      return;
   }
   //THIS FIXES ERROR 5004
   if (handle>0)
   //THIS FIXES ERROR 5004
   {
      Print("File open");
      FileWrite(handle,"Symbol","Ask","Bid"); //Name column headers
      FileSeek(handle, 0, SEEK_END); // go to end of file
      //Record Indicator values
      
      FileWrite(handle,
      Symbol(),
      Ask,
      Bid);      
      
      FileClose(handle); //Close file
   }
}
}

The errors were because the file was already open.
Florian Riedrich
396
Florian Riedrich  
Uhh yeah! You are so right :-)
Thanks!
To add comments, please log in or register