Hello there! The client encountered the error “cannot set millisecond timer(100)”when working with my expert Advisor. This happened for the first time in the history of the adviser. I studied the forum, but I didn’t find an answer to my question. I would like to know what the error can be here at all, that is, where to dig, what to ask. Thanks!
Share
prostotrader
No need for any cycles, do so and everything will work perfectly
//+------------------------------------------------------------------+
//| Timer_set.mq5 |
//| Copyright 2019, prostotrader |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, prostotrader"
#property link "
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
bool t_set;
//---
int OnInit()
{
t_set = EventSetMillisecondTimer(1000);
if(t_set = false)
{
Alert("Timer not set!");
return(INIT_FAILED);
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(t_set = true) EventKillTimer();
}
mosaddeqi
Hi guys,
I use
the iCustom () function in my expert Advisor, and when I attach it to the chart, “can’t set timer (1)” is shown in the expert tab!
I added this code to the OnInit () function, but the problem is still not solved!
Please help me!
Thank you for your feedback in advance!
falkovds
Let me explain how I see the problem.
I connect to the VPS via mstsc. I start the terminal, and in it I start the robot, which works on a timer. The timer may throw an error for unknown reasons. Or it may not give out, but start.
This loop tries to set the timer until it starts and returns the error ” 0 ” (this probability is preserved, and you can start it on the nth attempt). As soon as this happens, the loop ends and the program goes into a timer. Once again, the timer works, but for some reason it may give an error and go further. Without this loop, you can get an error at the initialization stage and switch to a non-working timer, which is unacceptable.
Then I see whether the timer has been initialized or not and decide what to do next. It is clear that I will not run the program and leave it on its own without making sure that it has at least started (passed the initialization stage). As soon as the timer is started, it already works without problems, and the program can be left disconnected from the VPS.
marketeer
An infinite loop? Well, well.
falkovds
Then so it is:
int error=-1;
int counter=1;
do
{
ResetLastError();
EventSetMillisecondTimer(Timer);
error=GetLastError();
Print(“EventSetMillisecondTimer. Attempt=”,counter,” Error=”,error);
if(error!=0) Sleep(1000);
counter++;
}
while(error!=0 && !IsStopped());
marys_fals
Thanks!))
kirillovyv
I added in OnInit():
int err=-1;
int count=5;
{while((err!=0)&&(count>0))
{
ResetLastError();
EventSetMillisecondTimer(MSTimerSet); //Setting the timer to XXX milliseconds
err=GetLastError();
Print(“EventSetMillisecondTimer n=”,count,” err >>”,err);
{if(err!=0){Sleep(50);}}
}}//while((err!=0)&&(count>0))
barabashkakvn
There is a very similar topic: cannot set millisecond timer (500)