Need a delete function for initial expert loading only.

 
My EA reads and executes 2 file names: 1-Trade is opened, 2=close. After the EA is enabled, I have instructed the EA to look for existence of File "close" and if it also finds the File "Trade is opened" delete both files together, provided there is no open trade, avoiding possible execution and opening of an unwanted trade after the initial start up and loading of the expert. So far so good. However, my problem starts when I try to delete the File"Trade is opened" at the Expert loading without the existence of the File"Close". Of course, I could just simply use File Delete function to do the job, but, if I do that then all of the incoming Files"Trade is opened" will be deleted and no trade will be executed. Is there any solution to the problem? I have included part of My EA here. Thank you for your help.
FCLOSE="CLOSE";
FB="TRADE IS OPENED";



//if no trade and close file received deltete it.
//====================================================================================
if(OrdersTotal()==0&&handle<0)
{
handle=FileOpen(FCLOSE,FILE_CSV|FILE_READ,';');
if(handle>0)
{
//==============================================
handle=FileOpen(FB,FILE_CSV|FILE_READ,';');
if(handle>0)
{
FileClose(handle);
FileDelete(FB);
}
//==============================================
FileClose(handle);
FileDelete(FCLOSE);
}}
 
Drop the files completely and just find out how many trades you have open
int start(){
    int count=0;
    for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS)                    // Only my orders w/
    &&  OrderMagicNumber() == Magic.Number                  // my magic number
    &&  OrderSymbol()      == chart.symbol                  // and my pair,
    ){ count++; }
    if (count == 0) Print("no trades open");
 
WHRoeder:
Drop the files completely and just find out how many trades you have open

Dear WHRoeder:


Thank you for your quick respond. I have already a separate function for deleting the files if there is order open. The problem occurs when there is no trade and I try to load the Expert.

 

Assuming you are using the file as a means of communicating with EA's attached to different Brokers.

Instead of deleting the file blank the file or write a zero to it not using 'append' mode.

 

Dear Ickyrus:


The problem occurs if the file still exists in the system and I try to load the expert say for the first time in a day.

 

Difficult to answer properly when what you are trying to do with the file is not clear.

 
Ickyrus:

Difficult to answer properly when what you are trying to do with the file is not clear.


Dear Ickyrus:


I will explain again. I need MY EA to delete any possible attached file when I load it for the first time each day. However, I do not want the EA to delete the same file after it has been loaded. That is, at the point of loading, if it finds any file to delete, but, after a few seconds of running it should not delete the same files if it receives them.

 
zaffrono:

Dear Ickyrus:


I will explain again. I need MY EA to delete any possible attached file when I load it for the first time each day. However, I do not want the EA to delete the same file after it has been loaded. That is, at the point of loading, if it finds any file to delete, but, after a few seconds of running it should not delete the same files if it receives them.

Add a delete routine into init() and check UninitializeReason() to see why the init() is being run.
 
Could also use time of day as a check. Write a batch file to delete the file when you turn the computer on (Unless Microsnot have disabled the Autoexec.Bat file option! - I'm not upto date on this aspect) Some info here
Reason: