Download MetaTrader 5

Time elapsed since EA began - page 2

To add comments, please log in or register
whroeder1
15331
whroeder1  
qjol: to activate the EventSetTimer() that's been set in OnInit u need a tick,
Call it from OnInit(), no tick needed
cryptex23
268
cryptex23  
RaptorUK:

Yep, the server time is updated on a tick, you can get it using TimeCurrent()


I've not used OnTimer() yet, but from the documentation it seems that you set the time using EventSetTimer() called from OnInit()


Ok so i am more or less done with my the mt4 part of my code. This eventsettimer, does it turn off the EA and start it again every 'x' seconds as specified or just takes away the execution rights from the EA for that while.

Is there any way i could execute another operation in between this time? say an important piece of data arrives in between this 'x' interval of time can i somehow operate on this data or do i have to wait till the 'x' seconds have passed away?

cryptex23
268
cryptex23  
cryptex:


Ok so i am more or less done with my the mt4 part of my code. This eventsettimer, does it turn off the EA and start it again every 'x' seconds as specified or just takes away the execution rights from the EA for that while.

Is there any way i could execute another operation in between this time? say an important piece of data arrives in between this 'x' interval of time can i somehow operate on this data or do i have to wait till the 'x' seconds have passed away?


Oh sorry my bad. using void Ontick would work solve the issue.

And is there any way to sync this eventsettimer with 00:00:00 hours? 00:00:30 next would be 00:01:00 next 00:01:30.....and so on. i was thinking of getting current time in seconds, then dividing it by 30 and use the greatest integer function. only when my current time is an integer multiple of it will the code give the signal for next 30 seconds. any other ideas?

Simon Gniadkowski
Moderator
18019
Simon Gniadkowski  
cryptex:


Oh sorry my bad. using void Ontick would work solve the issue.

And is there any way to sync this eventsettimer with 00:00:00 hours? 00:00:30 next would be 00:01:00 next 00:01:30.....and so on. i was thinking of getting current time in seconds, then dividing it by 30 and use the greatest integer function. only when my current time is an integer multiple of it will the code give the signal for next 30 seconds. any other ideas?

You can detect when Midnight has occurred since the last tick . . . if there is no tick from 5 seconds to Midnight till 5 seconds after you will miss the actual Midnight second. Alternatively just set the EventSetTimer() called from OnInit() to the number of seconds left before the start of the next minute or half minute and then in the first OnTimer() call reset the timer to 30 seconds.

To set the first timer . . .

int FirstOnTimerPeriod = 0;
static bool SetFirstTimerPeriod = false;

if(!SetFirstTimerPeriod)
   {
   FirstOnTimerPeriod = MathMin( TimeCurrent()%60, TimeCurrent()%30 );
   EventSetTimer(FirstOnTimerPeriod);
   SetFirstTimerPeriod = true;
   }


Then in OnTimer()

void OnTimer()
   {
   static boolsSetTimerTo30Secs = false;
      
   if(!SetTimerTo30Secs)
      EventSetTimer(30);  // reset to 30 seconds on first call


   }
12
To add comments, please log in or register