Start Timer Function

 

Hi,

 

I want to ask, how I can implement a function for starting a timer after a certain condition like

 

If buyCondition is true, then wait excactly 60 or defined seconds and check the buycondition again after the seconds are over.

I used in my code function like TimeSeconds(TimeCurrent()) which provides me the exact seconds, but how can I compare it with the current time.

For instance, if the seconds, where the buyCondition is true is 15 seconds, and normally I  have to add this to the current time and compare this  with

TimeCurrent(). How can I do this in Mql4?

 

Thanks for your help. 

Kind regards,

Hoschie 

 

When your buy condition is true:

EventSetTimer(60);

 

From within OnTimer(), kill the timer and check again for the buy condition

void OnTimer()
  {
   EventKillTimer();
    // now check your buy logic again
  }
 
Hoschie: If buyCondition is true, then wait excactly 60 or defined seconds and check the buycondition again after the seconds are over.
static datetime timer;
static bool buyCondition;
bool wasCondition = buyCondition; buyCondition = ...;
if(buyCondition && !wasCondition) timer = TimeCurrent();
if(TimeCurrent() - timer >= 60) CheckAgain();
Reason: