what timer, countdown?
There is a loop that counts down to show the history of incoming.
You only have to set it once in OnInit() function and not over and over in a do while loop.
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create a timer with a 1 second period EventSetTimer(1); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+
- Marco vd Heijden: You only have to set it once in OnInit() function and not over and over in a do while loop.
You have to on MT4, because sometime it returns an error (4030.)
EST can fail. The default suggestion is to loop until you enable it.
Build 1080 Cannot Set Timer error with EventSetTimer function - Indices - MQL4 programming forum #8I don't try to enable them in OnInit but instead I keep trying to enable them in OnTick/OnCalculate until they succeed. (No race condition, no CPU loop, no timer ticks before chart is updated.)
Cannot set timer (60) - EA not working - MT4 - MQL4 programming forumint OnInit(){ while(!EventSetTimer(1) ){ alert_id(StringFormat("EST:%i", _LastError) ); Sleep(5000); if(_StopFlag) return INIT_FAILED; }
1 09:31:41.071 order_graphic_tool_v6 USDCHF,Daily: cannot set timer (1)
0 09:31:41.071 order_graphic_tool_v6 USDCHF,Daily: Alert: order_graphic_tool_v6 USDCHF D1 EST:4030
0 09:31:41.071 order_graphic_tool_v6 NZDCAD,Daily: Alert: order_graphic_tool_v6 NZDCAD D1 EST:4030
1 09:31:41.071 order_graphic_tool_v6 GBPCHF,Daily: cannot set timer (1)
1 09:31:41.071 order_graphic_tool_v6 AUDSGD,Daily: cannot set timer (1)
0 09:31:41.071 order_graphic_tool_v6 GBPCHF,Daily: Alert: order_graphic_tool_v6 GBPCHF D1 EST:4030
0 09:31:41.071 order_graphic_tool_v6 AUDSGD,Daily: Alert: order_graphic_tool_v6 AUDSGD D1 EST:4030
1 09:31:41.071 order_graphic_tool_v6 USDCAD,Daily: cannot set timer (1)
1 09:31:41.071 order_graphic_tool_v6 GBPJPY,Daily: cannot set timer (1)
0 09:31:41.071 order_graphic_tool_v6 GBPJPY,Daily: Alert: order_graphic_tool_v6 GBPJPY D1 EST:4030
0 09:31:41.071 order_graphic_tool_v6 USDCAD,Daily: Alert: order_graphic_tool_v6 USDCAD D1 EST:4030
Jeovane Reges: I added the above code to the OnInit() function.In EA I'm using 5 second sleep, which usually doesn't result in a second attempt. For indicators try and set it in OnCalculate. On failure return zero and retry next tick. This drastically reduces the problem.
What are you doing? I dont understand.
It should be very easy. All you need are two built in functions.
int OnInit() { //--- create timer EventSetTimer(1); // Timer set to 1 second return(INIT_FAILED); } void OnTimer() // This function runs every time the Event timer goes off. { // do something here every second }
There can be set only one timer per script – so maybe your indicator is using some other timers? For example within the used script or other indicator?
But as others have mentioned – you should place EventSetTimer on the OnInit and I recommend also EventKillTimer added to OnDeinit function (there is no OnDeinit initially on the indicators schema but you can add it) or you can try first kill a timer and then restart it like that (I set it up to 10 attempts to not block the whole indicator):
void OnInit(){
bool set = EventSetTimer(1);
for(int i=0; i<10; i++){
EventKillTimer();
set = EventSetTimer(1);
}
}
Please edit your post and use "</>" or Alt-S to properly insert your code. Don't just use plain text. It becomes unreadable.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
After some internet searches I found the code below as a possible solution, but it didn't work.
Does anyone know what I can do?
Note: I added the above code to the OnInit() function.
Thank you.