Alternative to IsConnected()

 

IsConnected() within a continuous loop seems to take around a minute to react to a lost connection.

A timeout of execution of a submitted trade operation can take a few minutes to return to the client.

These durations are too long.

Are there any alternatives that would tell me in under 5s whether the connection with the server is still fine?

 
hyperdimension:

IsConnected() seems to take around a minute to react to a lost connection.

A timeout of execution of a submitted trade operation can take a few minutes to return to the client.

These durations are too long.

Are there any alternatives that would tell me in under 5s whether the connection with the server is still fine?


MT4 is reacting on incoming ticks The brokertime is not displaying every second because of that...

 

I'm calling IsConnected() from within a continuous loop, so code execution is not dependent on incoming ticks.

try running IsConnected() from within a continuous loop and then disconnect from the internet to see how long it takes for the terminal to realize that there is no connection.

 
hyperdimension:

IsConnected() within a continuous loop seems to take around a minute to react to a lost connection.

A timeout of execution of a submitted trade operation can take a few minutes to return to the client.

These durations are too long.

Are there any alternatives that would tell me in under 5s whether the connection with the server is still fine?

  1. That's the timeout between the terminal and the server. If you shutdown the network at your end, it will react immediately. I have Simple Internet Meter Lite - a repair network results in a disconnection immediately and when finished the terminal reconnects in several seconds.
  2. Of course, message can be lost in transit, server could be busy, etc.
  3. too bad - pay a million for a co-located server.
  4. return from start. When start is called again, you know you have a connection, no guarantee how long.
 
hyperdimension:

IsConnected() within a continuous loop seems to take around a minute to react to a lost connection.

I have written a tick recorder that continuously checks the return value of IsConnected() in addition to executing the main task of recording tick prices to file. I ran it on my VPS account physically located in Boston.

Here are some screen captures of the data that shows that it takes around a minute for the terminal to realize that the connection is lost.



A blank value in the spreadsheet for the isConnected column means the value was 1. When IsConnected() = 0, I have set the values for Bid and Ask to blank because any prices are invalid at such a moment. Additionally, the Bid and Ask prices prior to IsConnected() = 0 would also be invalid in hindsight.

There needs to be a better way to check the connection instead of relying on IsConnected().

 
hyperdimension:

IsConnected() within a continuous loop seems to take around a minute to react to a lost connection.

A timeout of execution of a submitted trade operation can take a few minutes to return to the client.

These durations are too long.

Are there any alternatives that would tell me in under 5s whether the connection with the server is still fine?

This is not my experience. Using this script ...

int deinit(){
   Comment("");
   return( 0 );
}

int start(){
   bool alert=true;

   while(true){
      if( IsConnected() ){
         Comment("Connected");
         alert= true;
      }
      else{
         Comment("NOT CONNECTED");
         if( alert )                   // so the alert only sounds once per event
            PlaySound("STalert2.wav");
            
         alert=false;   
      }
      
      Sleep(200);
   }
   
   return(0);
}

at the weekend, so no incoming ticks, I disabled the connection to the terminal by disabling the ethernet port (LAN) to the router. The connection window in the bottom right corner of the terminal window showed no connection in a varying amount of time (up to a few seconds) but the alert sounded immediately the connection dropped (ie as soon as the terminal showed a dropped connection). I am not sure if this emulates your problem closely enough though.

 

dabbler:

I disabled the connection to the terminal by disabling the ethernet port (LAN) to the router. The connection window in the bottom right corner of the terminal window showed no connection in a varying amount of time (up to a few seconds) but the alert sounded immediately the connection dropped (ie as soon as the terminal showed a dropped connection). I am not sure if this emulates your problem closely enough though.

I think the time the terminal takes to realize that a connection to the server is lost depends on exactly where the disconnection occurs. I have just tried "block network traffic" in ESET firewall on my computer and it took over a minute. Whereas when I disable "Local Area Connection" in Windows Control Panel, it took 7 seconds.

I think it would also take over a minute if you physically unplugged the network cable from the computer.

If you logged ticks with an IsConnected() check you'd often see the long price freezes just before IsConnected() = 0 as I've posted above.

 
hyperdimension:

I think the time the terminal takes to realize that a connection to the server is lost depends on exactly where the disconnection occurs. I have just tried "block network traffic" in ESET firewall on my computer and it took over a minute. Whereas when I disable "Local Area Connection" in Windows Control Panel, it took 7 seconds.

I think it would also take over a minute if you physically unplugged the network cable from the computer.

If you logged ticks with an IsConnected() check you'd often see the long price freezes just before IsConnected() = 0 as I've posted above.

That's useful information. Thanks for posting it.
 
Why don't you monitor how long it's been since TimeCurrent() has changed.
    int     startWaitingTime    = GetTickCount(),   // Remember start time.
:
    int delay = GetTickCount() - startWaitingTime ;
Why do you care? If a disconnection occurs then you can't trade. If you ignore them and try to open you'll get a timeout error and didn't trade.
 
WHRoeder:
Why don't you monitor how long it's been since TimeCurrent() has changed. Why do you care? If a disconnection occurs then you can't trade. If you ignore them and try to open you'll get a timeout error and didn't trade.

It matters when you are trying to analyze tick data and formulate statistics from it. Price freezes that were caused by lost connection with the server skews the data. Without checking IsConnected() you would never have known that those ticks with duration over 60s were invalid.

In real-time, it's better to know about a lost connection sooner than later instead of reacting to a trade timeout error which can take a minute (or up to 3 minutes) to appear after order submission during which time the trade context is occupied and therefore other orders cannot go through.

I don't see the point of recording the duration since TimeCurrent() has changed. I already log every single change in Bid or Ask price and the time of the price change in a continuous loop. Some ticks of long duration may still be valid. Using IsConnected() or a better alternative would help to weed out the invalid ticks.

Reason: