Metatrader / Windows update and Expert Advisers open positions

 
 What happens when there is an update and the expert advisor has an open position? It will lose all closing parameters set up within EA ? If that is so, is there a way to mitigate this situation ? Global Variables ? Store and retrieve parameters after the update is done ? The same question/doubt is also pertinent for a windows update with the need to reinitiate the computer. Any best practices here is available? Thanks .
 
52170755:
 What happens when there is an update and the expert advisor has an open position? It will lose all closing parameters set up within EA ? If that is so, is there a way to mitigate this situation ? Global Variables ? Store and retrieve parameters after the update is done ? The same question/doubt is also pertinent for a windows update with the need to reinitiate the computer. Any best practices here is available? Thanks .

You can setup custom structures within your ea (you already have them probably) for logging the state of the ea trades .

For instance if you have a trade element (that reflects to an actual trade of your ea) , draft example :

struct a_trade
{
long ticket;
bool trailed;
};

you can transform it into :

struct a_trade
{
long ticket;
bool trailed;
       a_trade(void){reset();}
     ~a_trade(void){reset();}
void reset(){ticket=-1;trailed=false;}
void save(int file_handle){
FileWriteLong(file_handle,ticket);
FileWriteInteger(file_handle,((int)trailed),INT_VALUE);       
}
void load(int file_handle){
reset();
ticket=(long)FileReadLong(file_handle);
trailed=(bool)FileReadInteger(file_handle,INT_VALUE);
}
};

Now you can write to the hard drive when the state of your trade or your system of trades changes . 

For example this can be (which probably already is) part of a bigger collection of structures that represent your system :

struct system{
a_trade mytrades[];
};

to which you add and remove like so :

struct system{
a_trade mytrades[];
int add_trade(long _ticket){
int ns=ArraySize(mytrades)+1;
ArrayResize(mytrades,ns,0);
mytrades[ns-1].ticket=_ticket;
return(ns-1);
}
void remove_trade(int _ix){
int ns=ArraySize(mytrades)-1;
mytrades[_ix]=mytrades[ns];
if(ns==0){ArrayFree(mytrades);}else{
ArrayResize(mytrades,ns,0);
}
}
};

and which you can save when changes occur with one call (and also load on outage , or update)

struct system{
a_trade mytrades[];
             system(void){reset();}
            ~system(void){reset();}
void reset(){ArrayFree(mytrades);}
int add_trade(long _ticket){
int ns=ArraySize(mytrades)+1;
ArrayResize(mytrades,ns,0);
mytrades[ns-1].ticket=_ticket;
return(ns-1);
}
void remove_trade(int _ix){
int ns=ArraySize(mytrades)-1;
mytrades[_ix]=mytrades[ns];
if(ns==0){ArrayFree(mytrades);}else{
ArrayResize(mytrades,ns,0);
}
}
void save(string folder,string filename){
int f=FileOpen(folder+"\\"+filename,FILE_WRITE|FILE_BIN);
if(f!=INVALID_HANDLE){
//# of trades 
  FileWriteInteger(f,ArraySize(mytrades),INT_VALUE);
  for(int i=0;i<ArraySize(mytrades);i++){
mytrades[i].save(f);  
}
FileClose(f);
}
}
bool load(string folder,string filename){
if(FileIsExist(folder+"\\"+filename)){
int f=FileOpen(folder+"\\"+filename,FILE_READ|FILE_BIN);
if(f!=INVALID_HANDLE){
int total=(int)FileReadInteger(f,INT_VALUE);
if(total>0){
ArrayResize(mytrades,total,0);
for(int i=0;i<total;i++){mytrades[i].load(f);}
}
FileClose(f);
}}
return(false);
}
};

And the loading function would need some checking of whether or not the trades are still there , just in case the "interruption" takes long

 

Lorentzos,

Thanks this is great and insightful information and will probably help all the community, not only myself. This is something that, at least myself , did not thought until it happens :) and it happens quite a lot. Again thank you very much !

Best , Andre