DAY1: Screenshot Manager

Home / Howtos / DAY1: Screenshot Manager

DAY1: Screenshot Manager


I had been developing indicators and EAs in MT4 MQL4 for about a year when I first came in touch with MT4GUI@FX1.
It was a “magical” moment, it was like finding something completely unique that the developers of MT4 “forgotten” to implement.
The functionality is amazing and the coding of it is rather easy, hey I can do it :-).

I will, in a miniseries of 10 blogs exploit MT4GUIs functionalities, with a daily blog update with new code example/functions.

I hope you find it interesting as well as valuable!


Thommy Tikka

DAY1: Objective

Who hasn’t been frustrated by the lack of an easy way to within MT4 take screenshots of the charts for POST-trade analysis!?
Now you can do it, and I will show you how!

DAY1: Functions covered


  • MT4 menu functions (Adding Options menu with submenus for enable/disable Screenshot button on chart and to set the screenshot size parameters)
  • MT4GUI button (Actual screen shot button on MT4 chart)
  • Look and feel (Size, color, rounded corners etc on menus and GUI object)
  • MT4 (MQL4)

  • WindowScreenShot (you will find your screenshots in the /MT4/Experts/Files/… directory)
  • Alert (pop-up box confirming user actions)

    // mt4gui-Screenshot.mq4
    // Created by Thommy Tikka ( 
    // Version 0.1, 20130401
    // Include library file with common functions for mt4gui
    #include <mt4gui.mqh>
    // Declare global variables
    int hwnd = 0;
    int screenshotBtn;
    int menuOptions,menuSubScreenshot, menuSubResolution, menuSubSub640, menuSubSub1024, menuSubSub1280;
    // Default Screenshot resolution set to 1024x768
    int screenShotResX=1024, screenShotResY=768; 
    // MT4 function called during the module initialization
    int init()
    	hwnd = WindowHandle(Symbol(),Period());	
       // Add screenshot button to chart function call
       // Add options menu to MT4 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 create Button
    void CreateScreenshotBtn()
    	// Position and size of the button ,x ,y ,a ,b (x, y = position from top left corner. a, b = size of button)
    	screenshotBtn = guiAdd(hwnd,"button",10,30,30,20,"");
    	// Screenshot button rounded corners radius
    	guiSetBorderRadius(hwnd,screenshotBtn, 10); 
    	// Screenshot button Border color
    	// Screenshot button Background color
    	guiSetBgColor(hwnd,screenshotBtn, Blue); 
    	// Screenshot button Text color
    	// Add "eye" webdings symbol to screenshot button
    // MT4GUI functions to create Menu
    void CreateOptionsMenu()
       // Add "Options" menu to MT4 menu 
    	menuOptions = guiAddMenu(hwnd,"Options",0,0);
    	// Add sub-menu Screenshot with enable/disable & sub-meny Resolution
    	menuSubScreenshot = guiAddMenu(hwnd,"ScreenShotBtn",menuOptions,1);
    	menuSubResolution = guiAddMenu(hwnd,"Resolution",menuOptions,0);
    	// Add sub-sub menu to Resolution menu
    	menuSubSub640 = guiAddMenu(hwnd,"Screen: 640x480",menuSubResolution,0);
    	menuSubSub1024 = guiAddMenu(hwnd,"Screen: 1024x768",menuSubResolution,0);
    	menuSubSub1280 = guiAddMenu(hwnd,"Sreen: 1280x1024",menuSubResolution,0);
    	// Set Options menu background color to Aqua
       // Set sub-menu Screenshot background color to Blue and text to White
    	// Set Screenshot meny item to enable
    // MT4GUI functions to capture Menu & Button Events
    void ManageEvents()
    	// If screenshotBtn is clicked execute function ScreenShotMT4
    	if (guiIsClicked(hwnd,screenshotBtn)) ScreenShotMT4();
       // If menuitem SubScreenshot is clicked check status, remove/create Screenshot button
       if (guiIsMenuClicked(hwnd,menuSubScreenshot)) 
          if (!guiIsMenuChecked(hwnd,menuSubScreenshot))
       // If menuitem SubResolution is clicked and a sub-sub menu resolution is choosed that one will be used for the screen shot (including Alert pop-up)
       if (guiIsMenuClicked(hwnd,menuSubSub640)) {screenShotResX=640; screenShotResY=480; Alert ("Screenshot resolution set to: 640x480");}
       if (guiIsMenuClicked(hwnd,menuSubSub1024)) {screenShotResX=1024; screenShotResY=768;Alert ("Screenshot resolution set to: 1024x768");}
       if (guiIsMenuClicked(hwnd,menuSubSub1280)) {screenShotResX=1280; screenShotResY=1024;Alert ("Screenshot resolution set to: 1280x1024");}
    // MT4 function for screen shot to file (...\'MT4-directory'\experts\files\...)
    void ScreenShotMT4()
       // Take screenshot based on pre-defined settings
       WindowScreenShot ("Button_"+Symbol()+"_M"+Period()+"_"+TimeToStr(TimeCurrent(),TIME_DATE)+"_"+Hour()+"."+Minute()+"."+Seconds()+".gif",screenShotResX,screenShotResX);
       // Alert user with a pop-up window
       Alert ("Screenshot taken (",screenShotResX,"x",screenShotResY,")");


    Thats all folks!

    Tomorrow I will show you how you can use preset trade comments in your trading.

    Leave a comment