Download MetaTrader 5
To add comments, please log in or register
Having difficulties in understanding the Trading Signals service? Read the article!
Samuel Oyeniyi
370
Samuel Oyeniyi 2015.03.21 14: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());
  }
  
   }        
}
whroeder1
13610
whroeder1 2015.03.21 14: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.
Samuel Oyeniyi
370
Samuel Oyeniyi 2015.03.21 18: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.
/
To add comments, please log in or register