Can't write to file when order is open

 

I have an EA that writes to a log file some info, at some points it decides to open an order and when this happens the EA doesn't write to the file anymore, I just get:

invalid integer number as parameter 1 for 'FileWrite' function

I'm attaching an screen shot: fo how when it opens the order the file handle doesn't change but for some reason it can't open the file any more. HELP!!

Log Error

 
You should have attached the relevant codes instead. Look at some file_write examples in the code base. Check reasons for error message in the Documentations.
 

Thank you, the code works fine, it creates the file when the EA is loaded, then on every tick I open the file, put tons of information in the file and then close it. But as soon as it opens an order it doesn't work anymore.

I searched this everywhere and I can't find any info on the error, I can't find anyone that's had the same problem, I can't find anyone with the same error, some people have had:

"invalid integer number as parameter 1 for TimeToNumber function"

But I can't find anything on:

"invalid integer number as parameter 1 for FileWritefunction"

 
favosys:

Thank you, the code works fine, it creates the file when the EA is loaded, then on every tick I open the file, put tons of information in the file and then close it. But as soon as it opens an order it doesn't work anymore.

I searched this everywhere and I can't find any info on the error, I can't find anyone that's had the same problem, I can't find anyone with the same error, some people have had:

"invalid integer number as parameter 1 for TimeToNumber function"

But I can't find anything on:

"invalid integer number as parameter 1 for FileWritefunction"

Your handle is invalid/not an int . . . fix your code. Perhaps you are using a locally declared variable with the same name as a globally declared variable, one an int and the other not an int. It's hard to help without seeing your code.
 

SUre, this is the code for the init function:

int init()

  {

//----

   File_Name = StringConcatenate(Name_of_file, " - ", Symbol(), " - ", TimeToStr(TimeLocal(),TIME_DATE), " - ", TimeHour(TimeLocal()), ".", TimeMinute(TimeLocal()), ".", TimeSeconds(TimeLocal()), ".txt");

   Handle=FileOpen(File_Name,FILE_CSV|FILE_WRITE,";");//File opening

   if(Handle==-1)                      // File opening fails

     {

      Alert("An error while opening the file. ",// Error message

              "May be the file is busy by the other applictiom");

      PlaySound("Bzrrr.wav");          // Sound accompaniment

      return;                          // Exir start()      

     }

     FileClose( Handle );

//----

   return(0);

  } 

So that just creates the file.

Then in the start function I open the file with:

Handle=FileOpen(File_Name,FILE_CSV|FILE_READ|FILE_WRITE,";");//File opening
    //Handle = 1;
    Print("Handle: ", Handle);
   if(Handle==-1)                      // File opening fails
     {
      Alert("An error while opening the file. ",// Error message
              "May be the file is busy by the other applictiom");
      PlaySound("Bzrrr.wav");          // Sound accompaniment
      return;                          // Exir start()      
     }
   FileSeek(Handle, 0, SEEK_END);

And then I write stuff in the file like:

Qnt_Symb=FileWrite(Handle,"**** STARTING TICK ", Symbol(), ": ", TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS), " ****");
Qnt_Symb=FileWrite(Handle,"************************************************************"); 

And then I close the file at the end

Qnt_Symb=FileWrite(Handle,"***************************");      
Qnt_Symb=FileWrite(Handle,"**** END TICK ", Symbol(), " ****");        
FileClose( Handle );
//----
   return(0);

And that's it.

Thanks for your help!

 
favosys:

SUre, this is the code for the init function:

So that just creates the file.

Then in the start function I open the file with:

And then I write stuff in the file like:

And then I close the file at the end

And that's it.

Thanks for your help!

Have you searched for ( Ctrl + F ) Handle in your code to find other declarations ? do you have any returns in start() other than at the end ? have you looked at the CSV file to see if it is complete ? if arts are missing it might give you some idea of what is or isn't being executed.
 
Handle=FileOpen(File_Name,FILE_CSV|FILE_WRITE,";");//File opening
Handle=FileOpen(File_Name,FILE_CSV|FILE_READ|FILE_WRITE,";");//File opening
Invalid last argument - not an int
 
RaptorUK:
Have you searched for ( Ctrl + F ) Handle in your code to find other declarations ? do you have any returns in start() other than at the end ? have you looked at the CSV file to see if it is complete ? if arts are missing it might give you some idea of what is or isn't being executed.


Hello Raptor UK,

There are no other Handle decalrations

The only other return is the one you see there when opening the file if Handle is -1

Not sure what you men if the file is complete. When the order opens the whole start function is processed and I know because the file has the last lines, the ** END TICKET ** lines so I know it got to the end and it closed the File.

What do you mean arts are missing? Sorry I don't know what arts are?

 
WHRoeder:
Invalid last argument - not an int


Hi WHRoeder,

What do you mean? The last argument of FileOpen is

delimiter - Delimiter character for csv files. By default, the ';' symbol applies.

Cheers

 
favosys:


Hello Raptor UK,

There are no other Handle decalrations

The only other return is the one you see there when opening the file if Handle is -1

Not sure what you men if the file is complete. When the order opens the whole start function is processed and I know because the file has the last lines, the ** END TICKET ** lines so I know it got to the end and it closed the File.

What do you mean arts are missing? Sorry I don't know what arts are?

Sorry, "parts" . . . do you get the **** END TICK USDCHF **** message ? or does it end before that ?
 
favosys:


Hi WHRoeder,

What do you mean? The last argument of FileOpen is

delimiter - Delimiter character for csv files. By default, the ';' symbol applies.

You have ";" not ';' . . . the error message you received talked about parameter 1, isn't that the file handle ?
Reason: