File write error

Back to topics list To post a new topic, please log in or register
avatar
6
samoye 2015.03.21 15:23
 

I am getting an error message while attempting to write to a file location.

 

0 16:13:12.522 HL GBPCHF,Daily: Alert: hist0935 Events File Error.5004

0 16:13:12.523 HL GBPCHF,Daily: Alert: hist0935 Events File Error.5004

0 16:13:12.525 HL GBPCHF,Daily: Alert: hist0935 Events File Error.5004

0 16:13:12.526 HL GBPCHF,Daily: Alert: hist0935 Events File Error.5004

0 16:13:12.529 HL GBPCHF,Daily: Alert: hist0935 Events File Error.5004

0 16:13:12.530 HL GBPCHF,Daily: Alert: hist0935 Events File Error.5004

 

Can somebody please help? 

//+------------------------------------------------------------------+
//| expert count strategy open position function  (openPos)          |
//+------------------------------------------------------------------+
void closedPos() {  

   int file=FileOpen("hist0935.csv",FILE_WRITE|FILE_CSV);
   
  
      
for(int i=OrdersHistoryTotal()-1; i>=0; i--) {

int file=FileOpen("hist0935.csv",FILE_WRITE|FILE_CSV);

ResetLastError();
file=FileOpen("hist0935.csv",FILE_WRITE|FILE_CSV);


      OrderSelect(i, SELECT_BY_POS, MODE_HISTORY); 

  if (file != INVALID_HANDLE){    

   PrintFormat("%s file is available for writing",file);
  
   
      FileWrite(file,OrderTicket(),OrderClosePrice(),OrderCloseTime());
      
      //--- close the file
     Print("error="+GetLastError());
      FileClose(file);
      PrintFormat("%s file is closed",file);
       
 }else{
      Alert("hist0935 Events File Error.",GetLastError());
  }
  
   }        
}
avatar
12985
WHRoeder 2015.03.21 15:33 #
 
int file=FileOpen("hist0935.csv",FILE_WRITE|FILE_CSV);
for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
    int file=FileOpen("hist0935.csv",FILE_WRITE|FILE_CSV);
  1. You open the file but don't check for an error What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. Then you try to open the file again, which fails. And you've lost the handle so you can't ever close it.
  3. Open once. Wight your data in the loop. Close after the loop.
avatar
6
samoye 2015.03.21 19:10 #
 
WHRoeder:
  1. You open the file but don't check for an error What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. Then you try to open the file again, which fails. And you've lost the handle so you can't ever close it.
  3. Open once. Wight your data in the loop. Close after the loop.
Thank you.
Back to topics list  

To add comments, please log in or register