Function execution in a specified time

 

Hi,

how can I code if I want a function of my EA is only executioning in a specified time. Example allways only in the 30th minutes of a hour.

if (Minute()==30 && Seconds()==0)
 {

....

}
Thanks for help.
 
Gabor Keresztessy:

Hi,

how can I code if I want a function of my EA is only executioning in a specified time. Example allways only in the 30th minutes of a hour.

Thanks for help.

There are many ways to do it, but I would probably do something like this

void OnTick()
{
   if(!ThirtyMinFunc())
      Print("It's not time yet");
}
//+------------------------------------------------------------------+
bool ThirtyMinFunc()
{
   static datetime last_bar_time = iTime(_Symbol,PERIOD_M30,0);
   if(iTime(_Symbol,PERIOD_M30,0) == last_bar_time)
      return false;
   Print("There is a new 30 minute bar! Processing 30 min function");
   last_bar_time = iTime(_Symbol,PERIOD_M30,0);
   /// do stuff
   return true;
}
 
nicholishen:

There are many ways to do it, but I would probably do something like this

Thanks for help, I'll try it soon.
Reason: