Download MetaTrader 5
To add comments, please log in or register
Learn operation principles of Trading Signals for MetaTrader.
Carl Schreiber
5932
Carl Schreiber 2015.07.17 10: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?

Files:
test_3.mq4 3 kb
JC
1389
JC 2015.07.17 11: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);
}
Carl Schreiber
5932
Carl Schreiber 2015.07.17 11:09  

Arrgh - you are right.

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

/
To add comments, please log in or register