Function to stop the EA 7 days before expiration date

 

Hi,

I'd like to stop the expert running on a symbol 10 days before the expiration date, how to using SymbolInfoInteger(SYMBOL_EXPIRATION_TIME) please ?



 
blouf:

Hi,

I'd like to stop the expert running on a symbol 10 days before the expiration date, how to using SymbolInfoInteger(SYMBOL_EXPIRATION_TIME) please ?



Which expiration date ?
 
angevoyageur:
Which expiration date ?
The contract expiration date. My broker use one for Jun, one for Jul etc ...
 
blouf:
The contract expiration date. My broker use one for Jun, one for Jul etc ...
Ah ok, in this case yes it should be SymbolInfoInteger(SYMBOL_EXPIRATION_TIME).
 
angevoyageur:
Ah ok, in this case yes it should be SymbolInfoInteger(SYMBOL_EXPIRATION_TIME).
Yes, but that's what it returns to me :
2014.05.22 08:13:53.034 2011.05.16 00:00:00   Heure courante : 1.3055e+009
2014.05.22 08:13:53.034 2011.05.16 00:00:00   Heure d'expiration : 1.40322e+009

For a 7-day before, should I use seconds to compare ?

EDIT : Yes it's seconds.

 
How to disable the EA from within the EA ?
 

So here it is : 

It seems to work, but I'd like not to remove the EA, just disable it.

Plus I got these (minors) errors ... how to correct them ?

possible loss of data due to type conversion    EA.mq5  1824    18
possible loss of data due to type conversion    EA.mq5  1825    19
void FinContrat()
{
datetime current = TimeCurrent(); 
datetime realend = SymbolInfoInteger(Symbol(),SYMBOL_EXPIRATION_TIME);
datetime localend = (SymbolInfoInteger(Symbol(),SYMBOL_EXPIRATION_TIME) - (DayBefore * 86400)); <---- DayBefore in days
if ((current > localend) && (!HaveLongPosition) && (!HaveShortPosition)) { 
printf("*** %S expire le %s (- %g jours) : désactivation de l'EA.",Symbol(), TimeToString(realend), DayBefore);
ExpertRemove();
}
}
 
blouf:

So here it is : 

It seems to work, but I'd like not to remove the EA, just disable it.

Plus I got these (minors) errors ... how to correct them ?

bool disabled=false;
void FinContrat()
  {
   datetime current = TimeCurrent();
   datetime realend = (datetime)SymbolInfoInteger(Symbol(),SYMBOL_EXPIRATION_TIME);
   datetime localend=((datetime)SymbolInfoInteger(Symbol(),SYMBOL_EXPIRATION_TIME) -(DayBefore * 86400));//<---- DayBefore in days
   if((current>localend) && (!HaveLongPosition) && (!HaveShortPosition)) 
     {
      printf("*** %S expire le %s (- %g jours) : désactivation de l'EA.",Symbol(),TimeToString(realend),DayBefore);
      disabled=true; //ExpertRemove();
     }
  }
void OnTick()
  {
   if(disabled)
   {
   ...
   return;
   }
   ...
  }
 
blouf:
How to disable the EA from within the EA ?

Please take a look at this function: ExpertRemove() 

 
Malacarne:

Please take a look at this function: ExpertRemove() 

I read it. The workaround from the traveling angel works also. So ... thanks :)
 
Malacarne:

Please take a look at this function: ExpertRemove() 

It seems to work, but I'd like not to remove the EA, just disable it.
Reason: