Problem with OnTimer()..

Back to topics list To post a new topic, please log in or register
avatar
2017
gooly 2015.07.17 12:58
 

Hi,

I want to make an EA tat is called/running once a day - but here in my test-code every hour.

It writes a comment with the time (local) of the last run and the time it should run the next time: one hour later.

BUT as you might see the OnTimer() seem to run every tick? Is that a bug or a feature?

void OnTimer()
  {
   int slp;
   while(!IsStopped()) {
      slp = 3600;
      strTme = StringConcatenate(myName," @ ",TimeToString(TimeLocal(),TIME_SECONDS),"  slp ",(string)slp," sec,  next Check(LocTme): ",TimeToString(TimeLocal()+slp));
      Comment(strTme);
      EventKillTimer(); // to kill existing thread to be safe
      EventSetTimer(slp);
      //Sleep(slp*1000);
      //DebugBreak();
   }
   Comment(strTme,"\n\nEA was stopped at: ",TimeToString(TimeLocal()));
   
  }

It seems as well that after some time the terminal runs at 99% cpu-usage?


Attached files:
  test_3.mq4  (2.25 KB)
avatar
1332
jjc 2015.07.17 13:04 #
 
gooly:

I want to make an EA tat is called/running once a day - but here in my test-code every hour [...]

Surely this enters OnTimer() for the first time and then never leaves it, because of the IsStopped() loop?

I don't understand why you're not doing something like the following:

int slp = 3600;

void OnInit()
{
  EventSetTimer(slp);
}

void OnTimer()
{
  strTme = StringConcatenate(myName," @ ",TimeToString(TimeLocal(),TIME_SECONDS),"  slp ",(string)slp," sec,  next Check(LocTme): ",TimeToString(TimeLocal()+slp));
  Comment(strTme);
}

avatar
2017
gooly 2015.07.17 13:09 #
 

Arrgh - you are right.

I first created a script to check the concept and copy and paste the code into the EA...

Back to topics list  

To add comments, please log in or register