FILEWRITE WON'T

 

Hi all;

this is likely something really dumb, the following code is right out of the forum, except i've added Print in order to debug and .

       int h1;
       h1 = FileOpen("trade_length.csv",MODE_CSV | MODE_WRITE |MODE_READ,";");Print("h1 = ",h1);
       if(h1<0)
        {
          Print("unable to open file trade_length.csv  ",GetLastError());
          return(false);
         }
      FileSeek(h1,0,SEEK_END);
      FileWrite(h1,High[1],Low[1],Close[1],Volume[1]);
      FileClose(h1);

So... compiles ok,... when run ....h1 is equal to -1, which means function failed and GetLastError is 4103 "cannot open file".... duh.

So the error is evidently in the h1 = FileOpen... line, but I'm damned if I can see anything wrong with it and the documents do

not indicate anything else that I need to do, i.e. the file is created by the ea when needed, I do not have to create it seperately.

Ideas, hints, suggestions, wild hunches and the correct solution all deeply appreciated.

Keith

 
int h1;
       h1 = FileOpen("trade_length.csv",FILE_CSV | FILE_WRITE |FILE_READ,";");Print("h1 = ",h1);
       if(h1<0)
        {
          Print("unable to open file trade_length.csv  ",GetLastError());
          return(false);
         }
      FileSeek(h1,0,SEEK_END);
      FileWrite(h1,High[1],Low[1],Close[1],Volume[1]);
      FileClose(h1);
 
Roger wrote >>

Many thanks Roger changing "Mode" to "File" solved the problem.

I got that snippet of code right out of Features of Expert Advisors, if it is no longer valid these guys oughta delete traps like this.

Thanks again

Keith

Reason: