Cannot set timer (60) - EA not working

 

This is the error I got when I running the EA. But some mt4 apps runs the EA perfect. But Exness broker mt4 gives this error to me.

Anyone can help me to fix this. 

 
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. I also get intermittent errors creating timers.
    1. There is a maximum number of timers, (somewhere above 60.)
    2. Various error codes (including 4024 and 4030.) So I don't enable them in OnInit but instead I keep trying to enable them in OnTick/OnCalculate until they succeed.
    3. I use a globally declared singleton of:
      class Ticker{
      // EventSetTimer sometimes fails in OnInit, on MT4, with internal error. So
      // remember to try it in OnCalculate
       public:
                  Ticker(void)    : mTickerStatus(false){}                    //[CTor]
       public:                                                             // Methods
         bool     enable(void){
            if(mTickerStatus != TS_ACTIVE){
               if(!EventSetTimer(1) ){
                  alert_id(StringFormat("EST:%i", _LastError) );
                  mTickerStatus  = TS_ERROR;
                  return false;
               }
               if(mTickerStatus == TS_ERROR) alert_id("EST: Successful");
               mTickerStatus  = TS_ACTIVE;
            }
            return true;
         }
         void     disable(void){ EventKillTimer();    mTickerStatus = false;       }
       private:                                                            // Data
            enum     TckStatus{   TS_IDLE,   TS_ERROR,   TS_ACTIVE   };
         TckStatus   mTickerStatus;
      }; // class Ticker
      

 
whroeder1:
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. I get errors creating timers also.
    1. There is a maximum number of timers, (somewhere above 60.)
    2. Various error codes (including 4024 and 4030.) So I don't enable them in OnInit but instead I keep trying to enable them in OnTick/OnCalculate until they succeed.
    3. I use a globally declared singleton of:
Can you explain more.
 
What is unclear?
 
Chathusanka Yamasinghe:

This is the error I got when I running the EA. But some mt4 apps runs the EA perfect. But Exness broker mt4 gives this error to me.

Anyone can help me to fix this. 

Trying to add this code onInit()

int count=0;
   bool timerset=false;      
   while(!timerset && count<5)
     {
      timerset=EventSetTimer(60);
      if(!timerset)
        {
         printf("Cannot set timer, error %s. Set trying %d...",(string)_LastError,count);
         EventKillTimer();
         Sleep(200);
         timerset=EventSetTimer(60);
         count++;
        }   
     }
   if(!timerset)
     {
      Alert("Cannot set timer");
      return INIT_FAILED;
     }
   else
     {
      printf("%s success on setting timer.",Symbol());
     }
 
Nguyen Quan Thanh:

Trying to add this code onInit()

Please insert the code correctly: when editing a message, press the button   Codeand paste your code into the pop-up window. (The first time I corrected your message)