Start Timer Function

Back to topics list To post a new topic, please log in or register
avatar
16
Hoschie 2015.08.07 13:06
 

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 

avatar
736
honest_knave 2015.08.07 14:14 #
 

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
  }

 

avatar
13009
WHRoeder 2015.08.07 14:59 #
 
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();

Back to topics list  

To add comments, please log in or register