It can be checked, just run the check in an infinite loop. how to start this loop when starting the terminal during a connection outage is a completely separate problem. Once you got your loop running it will do what is expected.
Your problem has nothing to do with the IsConnected() function. With the same argument you could also complain about Print() or Alert() or any other function that you cannot call because you could not start the entire code in the first place because of some completely different reason.
ok, Let me explain something Because I'm useing a lot Terminlas All along my cpu useage is rising up to 100 prcent that is why i need to turn off a few terminals
And when I turn them on (of course automatic) I saw a few times that they are not connected & the EA was running on them did not report that there is no connection,
that is y i started this topic & so far the only way that i found is like i said above whit an external program
Maybe it is related to the "feature" that was first introduced with Windows XP SP2 that it refuses to have more than only a handful of half-open connections at any time, mainly to annoy people who want to use networking intensive applications. AFAIK there exist methods to patch this annoying "feature" away and restore normal operability: http://blog.davidkaspar.com/archives/2005/04/windows-xp-sp2-and-event-id-4226.php
Look for the 4226 event in the windows event log.
This is nice but it doesn't always work because the tick may be gone even before initi() has returned, in which case the tick is discarded. To highlight this, if you add a 5ms pause after
PostMessageA(hwnd, msg, 2, 1); // enqueue a fake tick and let init() return
then start() will not be executed.
Is there a better solution to have start() execute on load of the expert advisor without requiring a real tick from the broker?
I little old but looking for a solution to the same problem I got on this topic.
In fact, assertion of qjol that "the only way to do this is whit a script; the problem is that there is no way to open the terminal with a script Loaded" is partially true. With a script ok, but there is a way to start a script with client terminal. This is documented in metatrader help (F1, Tools, Configuration at Startup). May be it's not same at the time of this topic was started.
So I developped a little script to do the job. Use this with a startup script, example :
; open chart and run expert and/or script
And lauch terminal with something like :
"...\Metatrader 4\terminal.exe" config\start.ini
Do you know any of you, why not work script fake ticks - https://www.mql5.com/en/forum/128803/page2#373539 (page 2) this thread for build 600++?
My OS is Vista. Thank you.
Since build > 600 you have to replace "A" for ansi with "W" for unicode
int PostMessageA(int hWnd,int Msg,int wParam,int lParam);
int RegisterWindowMessageA(string lpString);
why is it use 2 and 1 in parameter
PostMessageA(hwnd, msg, 2, 1)
It is out of scope of MQL, chet the function here:
In case someone else is searching for information regarding IsConnected() function.
So yes, the function will not work under start() function or OnTick() function, because if there is no connection, then no new tick will arrive, and the function will not trigger anyway....
So what should we do?
Use the OnTimer() function, to regularly check for connection, regardless of incoming ticks.
int timer = 60; //60 seconds, for example
//--- create timer
EventSetTimer(timer); //could use EventSetMillisecondTimer(timer) for millisecond resolution
// Metatrader self-triggered function, will be called regularly
Alert("Problem, not connection to the server!");
void OnDeinit(const int reason)
//--- destroy timer
You should do nothing, because there is nothing you can do. It takes 30+ seconds before the network times out and the function changes value. What are you going to do when nothing has changed and you have no connection?
It's only useful if you never return from start/OnTick (check it before a OrderSend.) Or after OrderSend for retries within the same tick.
Instead, if OrderSend fails, log it, return and test/retry on the next tick. Done.