Download MetaTrader 5

Function to stop the EA 7 days before expiration date

To add comments, please log in or register
Icham Aidibe
10315
Icham Aidibe  

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 ?



Alain Verleyen
Moderator
33351
Alain Verleyen  
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 ?
Icham Aidibe
10315
Icham Aidibe  
angevoyageur:
Which expiration date ?
The contract expiration date. My broker use one for Jun, one for Jul etc ...
Alain Verleyen
Moderator
33351
Alain Verleyen  
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).
Icham Aidibe
10315
Icham Aidibe  
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.

Icham Aidibe
10315
Icham Aidibe  
How to disable the EA from within the EA ?
Icham Aidibe
10315
Icham Aidibe  

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();
}
}
Alain Verleyen
Moderator
33351
Alain Verleyen  
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;
   }
   ...
  }
Rodrigo Malacarne
Moderator
10388
Rodrigo Malacarne  
blouf:
How to disable the EA from within the EA ?

Please take a look at this function: ExpertRemove() 

Icham Aidibe
10315
Icham Aidibe  
Malacarne:

Please take a look at this function: ExpertRemove() 

I read it. The workaround from the traveling angel works also. So ... thanks :)
Alain Verleyen
Moderator
33351
Alain Verleyen  
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.
To add comments, please log in or register