Login from script

 

Hi,

Is it possible to log in/log out from mql4 (with different credentials on different server)? I cannot see any command for such action in mql4. Is it possible to log in programmatically from dll using MetaTrader terminal instance log in mechanism (this is usually done via log in dialog in instance)?

Thanks for your help,

Aleksandar

 
apapic:

Is it possible to log in/log out from mql4 (with different credentials on different server)? I cannot see any command for such action in mql4.

MQL4 doesn't support this natively.


Is it possible to log in programmatically from dll using MetaTrader terminal instance log in mechanism (this is usually done via log in dialog in instance)?

One possible solution has been given in the Russian forum - login via PostMessageA() simulated keyboard strokes. Probably not a very reliable method, I wouldn't trust it for Live trading (IMHO). Anyway, have a look here -> https://www.mql5.com/en/forum/110932,


A better solution would be to start/restart the Terminal and "inject" it with the account details. Terminal.exe supports execution using a configuration file passed as a command-line parameter. This configuration file can have login, proxy, FTP and email settings, the state of experts, scripts and indicators at start, etc... The MT4 help file gives detailed examples of everything that could be configured this way (open the help file and search for 'tools - configuration at startup').

If u want to have one Terminal start another Terminal - this article has an example of how to do it -> https://www.mql5.com/en/articles/1467. If you want the Terminal to restart itself with different login details - use a method similar to what jjc describes here -> https://www.mql5.com/en/forum/123488.

 

gordon wrote >>

[...] If you want the Terminal to restart itself with different login details - use a method similar to what jjc describes here -> https://www.mql5.com/en/forum/123488.

And code to achieve what is described in the JJC thread can be found here...https://www.mql5.com/en/forum/126166
 
Viffer:
And code to achieve what is described in the JJC thread can be found here...https://www.mql5.com/en/forum/126166
Not really... It only exits the Terminal. Doesn't restart it. Exiting is the trivial part...
 
gordon:
Not really... It only exits the Terminal. Doesn't restart it. Exiting is the trivial part...
All relative I guess, restarting with windows scheduler was the trivial part for me... but damn if I couldn't work out how to exit terminal in the first place :) No doubt there are more elegant methods to restart terminal but that is way way way over my pay grade. Shoe horning in a scheduler botch at least gives me something that works.
 

Thanks a lot.

I found some solution, but it is still workaround. First, post command message with menu item Login ID, then hook into login dialog controls and set text for each one (Login, Password and Server) and finally send IDOK to login dialog. Everything is done in C++ dll.

 
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.
 
FourX:
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.

Please don't write the same post several times. This only pollutes the forum and annoys it's members. You can go ahead and delete the other 3 (!) identical posts: https://www.mql5.com/en/forum/126895, https://www.mql5.com/en/forum/126296, https://www.mql5.com/en/forum/110932/page2.


[...] how to find out when the account is sitting idle [...]

Depends on your definition of 'idle'.

[...] change to a different account # along with have the appropriate charts profile change along with them.

MT4 is not designed for this, hence the answers u got so far are incomplete and mostly discuss ways to 'go around' this problem. U can wait for MT5 which has built-in functions for changing accounts, etc. Otherwise, u can attempt implementing one of the suggestions on this thread.

IMHO, just do what everybody else does - use several Terminals. The great thing about MT4 is that it is extremely light on system resources. Even a WinXP box with 512mb can run up to ~10 Terminals with no problems.

 
As informed by Gordon, the Help files say that one can modify the start.ini file for startup options and might accomplish it that way. But looking in the config folder there is no actual start.ini file there at all. Perhaps it is optional. There is a number of other ones, most of which are complied. But there are two files:Terminal.ini and MetaEditor.Ini files that are text files, but for the most part they just have information about the physical layout and configuration of these two executable programs.
Reason: