How to make the advisor to run in the last 30 sec every hour?

 

Hi,


I want the Expert to run anytime in the last 30 seconds every hour (1H bars). I.e. anytime between XX.59.30 to XX.59.59 every hour. And only to be run once. Maybe I am just searching in the wrong way but I can only find how to run the EA at the start of the bar.


Thank you in advance

 
Well, catch the beginning of the bar, and then wait for  XX.59.30
 

Thank you,

Helped put my thoughts in the right direction


//Krilon

 
FX-Krilon:

Hi,


I want the Expert to run anytime in the last 30 seconds every hour (1H bars). I.e. anytime between XX.59.30 to XX.59.59 every hour. And only to be run once. Maybe I am just searching in the wrong way but I can only find how to run the EA at the start of the bar.


Thank you in advance

Just add this in as a condition


&& Minute() == 59

&& Seconds() >= 30

 
//timeframe H1

datetime endtime = Time[0]+Period()*60;

if(endtime-TimeCurrent()<=30) { do something ....}
 
   static bool isCharged=true;
   MqlDateTime dt;
   TimeCurrent(dt);
   if(dt.min==59 && dt.sec>=30 && isCharged) { FireLasers(); isCharged=false; }
   if(dt.min==00 && !isCharged) isCharged=true;
Like this maybe. Place it inside OnTick().
 
bool is_trade_time(int last_n_seconds, ENUM_TIMEFRAMES tf=PERIOD_H1)
{
   datetime stop_time = iTime(_Symbol, tf, 0) + PeriodSeconds(tf);
   datetime start_time = stop_time - last_n_seconds;
   datetime curr_time = TimeCurrent();
   return (curr_time >= start_time && curr_time < stop_time);
}