onTimer not called for me

 

hi,


I created a service and I want to run a code every 10 seconds and I use the following code but it does not working


int OnInit(){
   EventSetTimer(10);
   return(INIT_SUCCEEDED);
} 
   
void OnTimer(){
    Print("message...");
}

How can i do this?

 
Mohammad Bahadori:

hi,


I created a service and I want to run a code every 10 seconds and I use the following code but it does not working


How can i do this?

as you have it there it works just fine,  so either you are not running it properly or you have other errors in your code which we cannot see...

what does the compiler say when you compile?

what does the Expert log say when you run it? 

you should also kill the event timer when you have finished with it

 
   EventSetTimer(10);

Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (MT5/MT4+strict), it is trying to help you.
          What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
          Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

That call can fail. Use a bool and OnTick.

Reason: