Can an EA rescan server?

 
I'm testing my EA at the moment and looking at disaster recovery. I have noticed quite frequently, the terminal loses connection and doesn't always automatically re connect. It takes me to press the rescan server button to re establish connection. This can be some hours later if I'm away from my PC. I can't find anything in search, is there anyway to code the ea to try and reconnect if it loses connection?

Any pointers appreciated
Thanks
 
Viffer:
I'm testing my EA at the moment and looking at disaster recovery. I have noticed quite frequently, the terminal loses connection and doesn't always automatically re connect. It takes me to press the rescan server button to re establish connection. This can be some hours later if I'm away from my PC. I can't find anything in search, is there anyway to code the ea to try and reconnect if it loses connection?
Possible solutions:
  1. Automatically restart the Terminal -> https://www.mql5.com/en/forum/123488.
  2. Re-login via simulated keystrokes (WinAPI calls) -> https://www.mql5.com/en/forum/110932 . This would have to be changed to do what u want; I doubt it's going to be reliable though.
  3. Move your trading to a VPS or dedicated server near your broker. I have had similar problems in the past that disappeared overnight when I moved my trading to a dedicated server.
 
I advise u switch to a VPS but let your broker know about it too.
 
Thanks for the response guys, I've some reading to do!
 
I should reconnect. Mine always reconnects in about a minute. If your's doesn't then work with your broker, or switch to another.
 
WHRoeder:
[...] If your's doesn't then work with your broker, or switch to another.

In my experience it's not quite that simple. I've got demo accounts running with 15 different brokers and I think that at least 10 of them have had some sort of connection issue (i.e. not resolved by itself quickly) during the last two or three weeks. And I wouldn't necessarily use the other 5 because of their spread/charges, or because of counterparty risk issues etc.

I'm also yet to see a broker whose live accounts are bullet-proof. It tends to go in phases (with FXCM, for example, being very bouncy recently). Personally, I take the attitude that connection issues are to be expected and managed, not that connection issues can be disregarded if you find the right broker.

 

Sorry to drag this thread back up after 3 years, but this seems like the most sensible place for my questions.

1) Is it possible to artificially re-create this disconnection error when needed, in order to test possible fixes?

The only way I can think of to force the connection to drop is to completely sever the internet connection (either physically, or via firewall, or via software disconnect). However, when I re-connect then the terminal updates automatically before I can test my own re-connect method.

2) Would a script running an infinite loop, separated with Sleep(), and running RefreshRates() or placing a temporary pending order every "n" minutes force the terminal to try to re-connect?

Obviously, on the face of it, you would not want to put the trigger in the EA, because that would only run every tick, which would only happen if the terminal is still connected ...

... however, yesterday my live MT4 terminal seemed to disconnect somewhere between 3am and 4am in the morning, because it missed a trade at about 4:10am. The only way I know it must have disconnected is because the last trade was just before 3am and the terminal logs show it trying to re-connect in the exact same 1-minute bar that the trade was supposed to take place. The chances of it deciding to spontaneously re-connect at that exact point are slim (EA makes < 5 trades every 24 hours, on a 1-minute chart), which suggests it was caused to try to re-connect by the EA trying to make a trade. This makes little sense, because in order for the EA to have tried to trade it must have been receiving ticks, which suggests it was already connected. It took 1 or 2 minutes to re-connect. Is there one connection for price data, and one connection for trade requests? If so, would RefreshRates() actually work to refresh the connection, or would it be better to use something like a temporary pending order placed a long way from the price and then immediately deleted?

I would test this myself, but I have been unable to replicate the error reliably. Also, it doesn't seem to make a log entry when it loses connection, only when it re-connects, which complicates things further.

 
clerin6:

2) Would a script running an infinite loop, separated with Sleep(), and running RefreshRates() or placing a temporary pending order every "n" minutes force the terminal to try to re-connect?


I'm also interested in what happens when a call to RefreshRates() is made during disconnection. I want to know if it will create an error. If it turns out that it actually gets the terminal to try to reconnect, that would be great, but I am concerned it might cause an error.

 

clerin6:

. Is there one connection for price data, and one connection for trade requests?

Yup

If so, would RefreshRates() actually work to refresh the connection,

probably not the outbound connection. In fact I suspect it does no network activity, and just updates the Bid/Ask variables in the thread from elsewhere in the terminal (but that's just a guess on my part)


or would it be better to use something like a temporary pending order placed a long way from the price and then immediately deleted?

This would just invoke the same connection mechanism as trying to place the real order (with a retry mechanism), so no real benefit. I think. For more gory details see my posts in this thread How MQL4 Works (esp last one)



For most situations, trying to place the trade will start up the connection. Any connectivity issues are likely network or broker issues.