A bug that cannot be fixed

 

Hi all, recently I've developed a EA in MT5 and would like to transfer the transactions done in MT5 to MT4 through a set of programs offered in https://www.mql5.com/en/articles/189.

It composes of 2 programs, one each in MT5 and MT4. The bug that I have found was in the program in MT4 so I would like to seek assistance from you all.

When this has been compiled and run as a script, the following error displayed in Experts page in Toolbox window:

22:02:30 Copyist_positions EURUSD,M1: Error opening file 4103

22:02:30 Copyist_positions EURUSD,M1: ArrayInitialize function internal error

According to what MT4 document has stated, error 4103 is 'chart not found'. I've tried to debug and found out that error was come from the following coding:

int READS(string files,string &s[],bool resize)
  {
//--- open file for reading
   int handle=FileOpen(files+".csv",FILE_CSV|FILE_READ,";");
//--- if successful
   if(handle>0)
     {
      //--- set initial array size, if it first pass
      if(resize)ArrayResize(s,1);
      int cnt=0;
      while(true)// loop until break
        {
         //--- increase array size
         if(resize)ArrayResize(s,cnt+1);
         s[cnt]=FileReadString(handle);  // read string from the file
         FileSeek(handle,0,SEEK_CUR);    // seek at new position
         if(s[cnt]=="")break; // break
         cnt++;
        }
      ArrayResize(s,cnt);
      FileClose(handle);
     }
//--- if error
   else 
   Print("Error opening file ",GetLastError(),",",files,"Handle=",handle);
   return(cnt);// returns the number of lines read

The variable integer handle was -1. The file failed to open is "Translator positions.csv."

Some other programmers have reinstalled MT4 and MT5 and resolved this problem successfully but unluckily I didn't. As handle was -1, it's highly likely that "Translator positions.csv" is having a problem but I really could not figure out what the problem is. This csv file was located in my PC E:\Program Files\MetaTrader 5\MQL5\Files\MetaTrader 4\experts\files, where was suggested by the article.

Actually I need this program urgently (as I haven't got enough time to writ my MT4 version EA) so any inputs would be much appreciated.

Many thanks.

 

Does your MT4 installation reside in this directory ? E:\Program Files\MetaTrader 5\MQL5\Files\MetaTrader 4\

Is the file already open by another program ? maybe MT5 ?

 
RaptorUK:

Does your MT4 installation reside in this directory ? E:\Program Files\MetaTrader 5\MQL5\Files\MetaTrader 4\

Is the file already open by another program ? maybe MT5 ?


Thanks for your reply, RaptorUK.

Yes, my MT4 was installed in that directory, as instructed in that article.

MT5 was also run for sure since I have to test whether the trade opened in MT5 was copied to the corresponding MT4, as shown in that article as well. Would that be a problem? @.@

 
hftsang:


Thanks for your reply, RaptorUK.

Yes, my MT4 was installed in that directory, as instructed in that article.

MT5 was also run for sure since I have to test whether the trade opened in MT5 was copied to the corresponding MT4, as shown in that article as well. Would that be a problem? @.@

I haven't done very much with MT5 but I have done a little with CSV files in MT4, if I have a CSV file open in Excel and I try to write to the file from MT4 it will fail.

If you close MT5 so it doesn't have the file open will the MT4 code run without error ?

 
RaptorUK:

I haven't done very much with MT5 but I have done a little with CSV files in MT4, if I have a CSV file open in Excel and I try to write to the file from MT4 it will fail.

If you close MT5 so it doesn't have the file open will the MT4 code run without error ?


I see. But what interesting is for these two programs, the one in MT5 writes the file "Translator positions.csv" and the other in MT5 continuously reads this file, detects the outstanding positions recently updated in MT5 and does the same in MT4. So it's not possible that MT5 is closed.

But you've given me an insight. I just copy that program out, remarks all the irrelevant coding and just tests the file open function of my MT4. If it still doesn't work, I think it may be something in error other than the program coding. But indeed I did reinstall MT4 and MT5 already. Should I even have to reinstall OS? *.* Hope not. Thanks again.

 

You probably need to close the Filehandler in MT5 in order that MT4 can access the file.

Beside that if you are running on Vista/Win 7, have your terminals in C:/Program Files/* and you still have enabled UAC the both programs do not necessary have the rights to alter / access files in the directory. The files are most likely stored in the virtual pool managed by windows and not in the correct filesystem location.

just a few cents

//z

 
zzuegg:

You probably need to close the Filehandler in MT5 in order that MT4 can access the file.

Beside that if you are running on Vista/Win 7, have your terminals in C:/Program Files/* and you still have enabled UAC the both programs do not necessary have the rights to alter / access files in the directory. The files are most likely stored in the virtual pool managed by windows and not in the correct filesystem location.

just a few cents

//z


Thanks, zzuegg. Luckily, I run in WinXP so the access right problem should be much easier to handle. Any similar issue if using administrator or other user profiles in WinXP? Well, maybe I have to check the access settings among the paths in MT4.

BTW, I copy part of the source program in MT5 related to the write file function as follows for your reference:

//+------------------------------------------------------------------+
//| write positions states to a csv file                             |
//+------------------------------------------------------------------+
void WriteFile(string folder="Translator positions")
  {
//--- open file for writing, shared read mode
   int han=FileOpen(subfolder+"\\experts\\files\\"+folder+".csv",FILE_WRITE|FILE_SHARE_READ|FILE_ANSI,",");
   if(han!=INVALID_HANDLE)// file opened successfully
     {
      string com=""; // comment
      FileWrite(han,(string)cnt_command); cnt_command++;
      for(int i=0;i<TotalSymbols;i++)
        {
         //--- write position state on symbol, specified in Symbols[i]
         FileWrite(han,
                   //--- position symbol
                   Symbols[i],
                   //--- position volume
                   DoubleToString(prevSymPosVol[i],DigitsStepLot(Symbols[i])),
                   //--- position type
                   (string)prevSymPosType[i],
                   //--- position stop loss
                   DoubleToString(prevSymPosSL[i],(int)SymbolInfoInteger(Symbols[i],SYMBOL_DIGITS)),
                   //--- position take profit
                   DoubleToString(prevSymPosTP[i],(int)SymbolInfoInteger(Symbols[i],SYMBOL_DIGITS))
                   );
         //--- comment
         com=com+"\n"+
             //--- position symbol
             Symbols[i]+"  [ "+
             //--- position volume
             DoubleToString(prevSymPosVol[i],DigitsStepLot(Symbols[i]))+" ]  [ "+
             //--- position type
             (string)prevSymPosType[i]+" ]  [ "+
             //--- position stop loss
             DoubleToString(prevSymPosSL[i],(int)SymbolInfoInteger(Symbols[i],SYMBOL_DIGITS))+" ]  [ "+
             //--- position take profit
             DoubleToString(prevSymPosTP[i],(int)SymbolInfoInteger(Symbols[i],SYMBOL_DIGITS))+" ]"
             ;
        }
      //--- close file
      FileClose(han);
      //--- print comment
      Comment((string)(cnt_command-1),com);
     }
//--- if file open has failed
   else Print("File open has failed"+subfolder+"\\"+folder+".csv, error",GetLastError());

It's using FILE_WRITE|FILE_SHARE_READ|FILE_ANSI already and also a FileClose at the end. Any ideas?

 
hftsang:


22:02:30 Copyist_positions EURUSD,M1: Error opening file 4103

22:02:30 Copyist_positions EURUSD,M1: ArrayInitialize function internal error


The variable integer handle was -1. The file failed to open is "Translator positions.csv."

Some other programmers have reinstalled MT4 and MT5 and resolved this problem successfully but unluckily I didn't. As handle was -1, it's highly likely that "Translator positions.csv" is having a problem but I really could not figure out what the problem is. This csv file was located in my PC E:\Program Files\MetaTrader 5\MQL5\Files\MetaTrader 4\experts\files, where was suggested by the article.

Can you close down MT4 then check the following folder: E:\Program Files\MetaTrader 5\MQL5\Files\MetaTrader 4\experts\logs\ and look for this file: 20110817.log open it an make sure you have the same/very similar error as you mentioned above.
Reason: