MT4 platform restart

 

Is there any code that restarts MT4 platform.

I remember I met in the past but forgot to

save it.

 

Hum. I'm interested in such a code myself. What I'm currently doing is using Windows Schedule Task. It tries to Open/Lunch Meta Trader every minute. If it's already opened by Schedule Task then you wouldn't notice anything the following minute.

I'm also having Schedule Task close the program at 11:45 pm everyday and reopen at 11:46. For some odd reason in the past the terminal lost connection to the server and did not auto-connect like usual. To solve that problem I had to close and reopen meta-trader. Rescan server would solve that problem as well but thats the code I'm looking for. 

 

I think some DLL has to be used. But let us wait what Gordon says.
 
Brygada:
I think some DLL has to be used. But let us wait what Gordon says.
Not much I am afraid. Never tried it myself (never needed to). There's some info here -> https://www.mql5.com/en/forum/123488.
 
void CloseTerminal() {
int hwnd=WindowHandle(Symbol(),Period());
int hwnd_parent=0;
//----eesfx.com
while(!IsStopped())
{
hwnd=GetParent(hwnd);
if(hwnd==0) break;
hwnd_parent=hwnd;
}
if(hwnd_parent!=0)
PostMessageA(hwnd_parent,WM_CLOSE,0,0);
//----eesfx.com
return(0);

}

http://eesfx.com

 
eliteeservices:
void CloseTerminal() {
int hwnd=WindowHandle(Symbol(),Period());
int hwnd_parent=0;
//----eesfx.com
while(!IsStopped())
{
hwnd=GetParent(hwnd);
if(hwnd==0) break;
hwnd_parent=hwnd;
}
if(hwnd_parent!=0)
PostMessageA(hwnd_parent,WM_CLOSE,0,0);
//----eesfx.com
return(0);

}

http://eesfx.com

Thank you for posting that code. I have been trying to work out how to do that for ages. Combined with the scheduler idea and this

https://www.mql5.com/en/code/7744


I think I have finally solved my lost connection issue

Thanks again

V

 

Damn it!! so close...


Ok, my intention is to use IsConnected.mq4 to test the connection status and if it remains disconnected for 5 mins, restart the terminal. When I do this manually after losing connection for a time (without internet problems) then it normally logs me back in straight away. Occasioanlly, it will take longer then 5 mins to re establish connection though.

So I can get it to test with IsConnected.mq4, shut down with the CloseTerminal() function and restart with scheduler... which for me is a major step forward, but I'm getting stuck when it re opens but then doesn't establish connection. My EA is only initialised after connection is established, so if there is still no connection, it just sits there without loading the EA. Ideally it needs to detect that there is still no connection, shut down and try again. Any ideas??

I think the above actions will solve about 80% of my issue which is great and I may just have to live with the 20%, But it would be great if I could finally tick this one off the list for good so ideas welcome.

And just to confirm, this connection loss doesn't appear to have anything to do with my actual connection... I lost connection for 35mins on Friday yet still had normal internet access and was even able to succesfully ping the brokers server...

 

Ok, forward testing, I'm 2 for 3 on this re connection issue so a big win as far as I'm concerened... when the connection is lost, it writes to a log file, tests connection status every 30 seconds for 5 minutes writes to the log if it reconnects, but if there is still no connection after 5 mins, the terminal shuts itself down and sheduler re starts it upon which if succesful it writes the reconnection to the log. Twice I have succefully regained connection and one time it failed to connect on opening and just sat there and took manual intervention. Critically, the EA will not initialise if the terminal does not gain connection so I have no way to identify if I do not get connected at restart. Is there any way around this? Should I just accept that I'll get a push email to the phone at 3am telling me it needed to restart and I should go check it connected OK?

Thanks for input

V

 
I don't need to know how to start MT4 other than us doing it ourselves. My quandary is how to find out when the account is sitting idle and then change to a different account # along with have the appropriate charts profile change along with them.
 
Create a batch file and schedule it (per minute?)
@echo off
set term="%ProgramFiles(x86)%\Interbank FX Trader 4\terminal.exe"
tasklist | findstr "terminal.exe" >nul
if ERRORLEVEL 1 start "terminal" %term%
Reason: