DAY3: Simple EA-login manager

Home / Howtos / DAY3: Simple EA-login manager

DAY3: Simple EA Login Manager


Welcome to Blog No 3 in this miniseries of 10 daily blogs in which I will exploit MT4GUIs functionalities.

I hope you find it both interesting as well as valuable!


Thommy Tikka

DAY3: Objective

Does your family & friends use your computer now and then?
Afraid that they will start your EA without knowing how to handle it?
Don’t be, with this piece of code you are the only one allowed to start it!

DAY3: Functions covered


  • MT4GUI labels (build a login panel with labels)
  • MT4GUI textfield (to be able to manually type a username & password)
  • MT4GUI button (Login, exit and move panel buttons on MT4 chart)
  • MT4GUI terminal function (get chart width and height for default GUI positioning)
  • Look and feel (Size, color, positioning etc of GUI objects)
  • MT4 (MQL4) & Windows

  • Windows dll call (used for exit EA from within code (advanced))
  • Alert (pop-up box confirming user actions)

    // mt4gui-SimpleEALogin.mq4
    // Created by Thommy Tikka ( 
    // Version 0.1, 20130403
    // Include library file with common functions for mt4gui
    #include <mt4gui.mqh>
    // Include library and import dll to be able to remove EA from chart automatically (advanced)
    #include <WinUser32.mqh>
    #import "user32.dll"
    int GetAncestor(int, int);
    // Declare global variables
    int hwnd = 0;
    int loginBtn, exitBtn;
    int moveUpBtn, moveRightBtn, moveDownBtn, moveLeftBtn;
    int loginHeader, loginPanel;
    int usernameTextField, passwordTextField;
    int gUIXPosition, gUIYPosition;
    int authenticationFail=0;
    // User credentials (fill in the ones you want to use)
    string username = "Administrator",
           password = "Password";
    // MT4 function called during the module initialization
    int init()
    	hwnd = WindowHandle(Symbol(),Period());	
       // Measures chart width and height and sets default GUI X/Y-positions to center of the chart
       gUIXPosition = guiGetChartWidth(hwnd)/2-90;
       gUIYPosition = guiGetChartHeight(hwnd)/2-85;
       // Add interface with panel and buttons to chart function call
    // MT4 function called during deinitialization of the module
    int deinit()
       // Very important to cleanup and remove all gui items from chart
       if (hwnd>0) guiRemoveAll(hwnd);   	
    // MT4 function called on every MT4 tick
    int start()
       // Call function ManageEvents on every MT4 tick
    // MT4GUI functions to capture Menu & Button Events
    void ManageEvents()
    	// If exitBtn is clicked execute function ExitEA()
    	if (guiIsClicked(hwnd,exitBtn)) ExitEA();
    	// If loginBtn is clicked execute function LoginEA()
    	if (guiIsClicked(hwnd,loginBtn)) LoginEA();
    	// If moveBtns are clicked change the default X/Y coordinates accordingly (Remove all objects and rebuild interface)
    	if (guiIsClicked(hwnd,moveUpBtn)) {gUIYPosition = gUIYPosition-10; guiRemoveAll(hwnd); BuildInterface();}
       if (guiIsClicked(hwnd,moveRightBtn)) {gUIXPosition = gUIXPosition+10; guiRemoveAll(hwnd); BuildInterface();}
       if (guiIsClicked(hwnd,moveDownBtn)) {gUIYPosition = gUIYPosition+10; guiRemoveAll(hwnd); BuildInterface();}
       if (guiIsClicked(hwnd,moveLeftBtn)) {gUIXPosition = gUIXPosition-10; guiRemoveAll(hwnd); BuildInterface();}
    // MT4GUI functions to build Interface with labels, buttons & textfields
    void BuildInterface()
       // Build Login panel (labels) and set look and feel for it
     	loginHeader  = guiAdd(hwnd,"label",gUIXPosition,gUIYPosition,180,20,"Please login:");  
    	loginPanel   = guiAdd(hwnd,"label",gUIXPosition,gUIYPosition+20,180,150,""); 	
       // Create buttons, Login & exit and set look and feel for them
    	loginBtn = guiAdd(hwnd,"button",gUIXPosition+100,gUIYPosition+110,70,40,""); 
    	guiSetBgColor(hwnd,loginBtn, Blue);
    	guiSetText(hwnd,loginBtn,"Login",25,"Arial Bold");
       exitBtn = guiAdd(hwnd,"button",gUIXPosition+10,gUIYPosition+110,70,40,""); 
    	guiSetText(hwnd,exitBtn,"Exit",25,"Arial Bold");
       // Create four arrow buttons, for move panel
       moveUpBtn = guiAdd(hwnd,"button",gUIXPosition+80,gUIYPosition-20,20,20,""); 
    	moveRightBtn = guiAdd(hwnd,"button",gUIXPosition+180,gUIYPosition+80,20,20,""); 
    	moveDownBtn = guiAdd(hwnd,"button",gUIXPosition+80,gUIYPosition+170,20,20,""); 
    	moveLeftBtn = guiAdd(hwnd,"button",gUIXPosition-20,gUIYPosition+80,20,20,""); 
    	//Add a username and password text field for manual input using user adjustable X/Y-position (size fixed to 150x20)
    	usernameTextField = guiAdd(hwnd,"text",gUIXPosition+10,gUIYPosition+40,160,20,"Username");	
       passwordTextField = guiAdd(hwnd,"text",gUIXPosition+10,gUIYPosition+70,160,20,"Password");
    // Windows/MT4 function to exit EA (advanced)
    void ExitEA()
       Alert ("This exits your EA");
            int hWnd = WindowHandle(Symbol(), Period());
            #define MT4_WMCMD_REMOVE_EXPERT   33050 /* Remove expert advisor from chart */ 
            PostMessageA(hWnd, WM_COMMAND, MT4_WMCMD_REMOVE_EXPERT, 0);
    // MT4GUI function check textfields (username & password), MT4 pop-up alerts
    void LoginEA()
       //Check that Username and password are correct
       if (guiGetText(hwnd,usernameTextField)==username && guiGetText(hwnd,passwordTextField)==password)
       {Alert ("Authorization successful (call your own function for continuation of EA execution)");guiRemoveAll(hwnd);authenticationFail=0;}
       else if (authenticationFail==0)
       {Alert ("Authorization failed, please try again (you have 2 of 2 retries left)"); authenticationFail++;}
       else if (authenticationFail==1)
       {Alert ("Authorization failed, please try again (you have 1 of 2 retries left)"); authenticationFail++;}
       else if (authenticationFail==2)
       {Alert ("Authentication failed 3 times, this blocks your login"); guiEnable (hwnd, loginBtn,0);}


    Thats all folks!

    Tomorrow I will show you how you can use MT4-Terminal/chart functions with MT4GUI.

    1 Comment Responses to DAY3: Simple EA-login manager
    Bransondot2017-02-23 09:49:19Reply free money on gta 5 online gta 5 cheats xbox 360 guns gta 5 story mode money cheat code xbox 360 paypal adder android
    Bransondot2017-02-22 14:37:49Reply
    Bransondot2017-02-22 10:18:55Reply
    GilberzTub2017-02-22 03:15:52Reply
    levitra 10mg or 20mg new posts - generic levitra online levitra 20 mg street value announcements levitra 20 mg - levitra vs levitra vs levitra which is better msboard.cgi?id= levitra dosage for maximum effect
    Bransondot2017-02-21 20:16:11Reply
    Bransondot2017-02-21 15:48:40Reply
    Bransondot2017-02-21 11:31:12Reply
    Zachezywef2017-02-21 11:20:52Reply
    indian viagra - viagra without prescription levitra vs viagra vs viagra reviews guestbook.php?page= viagra without prescription - viagra 20 mg 8 table username viagra 20mg memberlist
    Bransondot2017-02-21 07:02:31Reply
    Bransondot2017-02-20 18:43:19Reply
    Bransondot2017-02-20 14:17:39Reply
    TonilykUsaps2017-02-20 06:07:53Reply
    TonilykUsaps2017-02-19 13:17:59Reply
    TonilykUsaps2017-02-19 11:50:52Reply
    TonilykUsaps2017-02-18 20:20:18Reply
    DelmezHem2017-02-18 17:25:11Reply
    viagra dosing options status - viagra without a doctor prescription viagra generic online viagra without prescription - buy viagra online no prescription masturbatrix viagra
    TonilykUsaps2017-02-18 14:24:16Reply
    MichaelCek2017-02-18 14:22:29Reply
    There are also uncountable sectors of canadian pharmacy, while the community posologist best canadian pharmacy online is a relaxed catch sight of, there are pharmacists that in the planning stages unemployed as pharmaceutical scientists - canadian pharmacy online, in the direction of case, developing drugs & manufacturing processes of canadian pharmacies shipping to usa
    TonilykUsaps2017-02-18 10:36:47Reply
    TonilykUsaps2017-02-18 05:09:23Reply
    Free Online GTA 5 money adder free paypal money adder online
    TonilykUsaps2017-02-17 15:05:48Reply
    Free Online GTA 5 money adder
    RoofusUnoky2017-02-15 21:07:31Reply
    doodidiopdn asdklasjdasodasd diuhhfjndbvd ddklddjdl
    EdzinWouff2017-02-10 13:23:07Reply
    cialis 4 women - cialis over counter buy lily cialis cialis over the counter at walmart - cialis and woman cialis 10mg or 20mg who is online
    LuciuzSteah2017-02-09 11:01:21Reply
    cialis online no prescription - cialis over the counter at walmart cialis impotenza condanna penale cialis over the counter at walmart - generic cialis worldwide cialis 20 mg coupon name
    ZilliamStype2017-01-30 03:40:46Reply
    should i take cialis before or after i eat - cialis without doctor prescription vipps approved pharmacy for cialis cialis without a doctor prescription usa - cialis dosage positive 1 diabetes and ed
    AaronzjeK2017-01-26 02:52:33Reply
    viagra daily overcomes meth ed - viagra without doctor prescription viagra 20mg tablets total posts viagra without a doctor prescription usa - viagra coupon cvs threads can a man take semenax and viagra at the same time.
    JazonMUT2017-01-22 05:52:18Reply
    viagra and alcohol side effects memberlist - viagra without a doctor prescription is it safe to take viagra viagra without a doctor - low cost viagra viagra 20 mg street value registered users
    Lazryspazy2017-01-22 02:13:38Reply
    natural ed treatment - cialis without a doctor's prescription cialis 1 dollar 99 cents special offer cialis without a doctor's prescription - purchase cheap cialis online cialis canadian pharmacy no prescription register an account
    Melzinpieft2017-01-17 19:43:25Reply
    cialis 10mg total topics - generic cialis cialis 20mg canada return to board index generic cialis - cialis pills for sale posts per day cialis vs cialis vs levitra which is better msboard.cgi?id=
    Lestezdus2017-01-09 22:37:05Reply - viagra without a doctor generico viagra viagra no prescription - generic viagra india cheapest how does viagra work
    Seeger2014-08-18 18:23:10Reply
    I´m german, and Mr. Google says: Hi Thommy, You've created many very nice applications. Unfortunately I am not a programmer, but I would still like to try it. After all, I have a very "simple" task? I would like a button in the chart with changing functions: "Start" (green) of the EA can be turned on, then "Stop" (red) of the EA can be turned off. Which existing code I might build. For a hint / help I would be very grateful. I wish a nice day.
    Leave a comment