Download MetaTrader 5
To add comments, please log in or register
Deposit to your account in any convenient way. There are 4 of them here!
Erkan Isik
64
Erkan Isik 2015.08.07 11: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 

honest_knave
969
honest_knave 2015.08.07 12: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
  }
whroeder1
13640
whroeder1 2015.08.07 12: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();
/
To add comments, please log in or register