Quick Start

Home / Quick Start

Quick Start Guide

×


This page is designed for impatient or advanced developer. This page allows you to understand core concept or MT4GUI under 10 Minutes. Please refer our full-documentation for all other details.

What is MT4GUI

MT4GUI allows you to build Graphical User Interfaces (GUI) on Metatrader4 using MQL4. We provide you a set of commands to build, manage, adjust and cleanup the GUI. MT4GUI also contains a set of functions which allow you to manage terminals such us closing, focusing, opening and browser by given default URL etc.

Installation

Being an advanced developer, you should know how to use a MQH File in MQL. We provide you MT4GUI.MQH file in our Downloads section. Download it and copy it into experts\include\ folder and then open it and compile it using Metaeditor. After downloading MQH file, please download MT4GUI.DLL file from the same Downloads section and place it in experts\libraries\ folder. The installation is done. It’s also essential that you have “Import of DLL Calls” enabled in Metatrader Options.

Hello World

Its common to write a HelloWorld Application

// HelloWorld for MT4GUI 
// Lets include the imports file mt4gui.mqh
#include <mt4gui2.mqh>
 
// global Variable
int hwnd = 0;
int button1 = 0;
 
int OnInit()
  {
    hwnd = WindowHandle(Symbol(),Period()); 
    // Version shall be displayed as comment
    Comment("MT4GUI Version : "+guiVersion());          
    // mark your clients with your apikey - optional - available from version 2.6
    guiVendor("259495BDD3F940996B5FF5475EB0BFFE");
    // In case there have GUI Items on chart, lets remove them all
    guiRemoveAll(hwnd); 
    // Add a button to Chart by 100,100 Coordinate, Width 100 and Height 30
    // Button caption "Click Me"
    button1 = guiAdd(hwnd,"button",100,100,100,30,"Click Me");
    // Every GUI Item returns a handle
  return(0);
  }
 
 
 
 
int OnDeinit()
  {
   // Very important to cleanup and remove all gui items from chart
   if (hwnd>0) { guiRemoveAll(hwnd);    guiCleanup(hwnd);}
   return(0);
  }
 
 
void OnTick()
{
  // Button GUI Item has Clicked Event to capture
  // You can use "guiIsClicked" command to capture the event
  if (guiIsClicked(hwnd,button1)) PlaySound("ok.wav"); 
}

Result

Demo2

×

Cheat Sheet


We have prepared a cheat-sheet for you to get started rapidly. We regularly update this cheat-sheet, please update your file from time to time.

Video Demonstration

Use this video to get started with mt4gui, this video does not cover everything but it is enough to get started. (watch it in HD)

New Vendor Feature

Important Facts

HelloWorld demonstration code written in MQL, using MT4GUI, demonstrates a very basic interface which shows one simple button on the chart and upon clicking which it plays a sound to demonstrate the click event. Most of MT4GUI Functions accept HWND as first parameter; it’s a Chart handle and is unique. So it’s a good idea to read it inside init () and keep it global. Important for Indicators: Because HWND is very a important parameter to pass to MT4GUI Functions, it’s essential that you read it before you call first MT4GUI Function. Due to some limitations on MQL and Metatrader, indicators may return 0 by WindowHandle() MQL Function if you start Metatrader4 and your indicator is already applied on the chart. Being a developer, you may notice this fact, and you must develop your own init() function if WindowHandle() returns 0. Under normal conditions, WindowHandle() native MQL Function should never return 0 because a HWND handle is always >0.

Generally we do need to Initialize and Build GUI and then deinitialize it upon close of chart. HelloWorld demonstrates all of these steps. It’s essential to clean up the interface in every deinit (), so to have deinit () function calls similar to HelloWorld in all your codes.

Every GUI Item returns a handle (see button1 variable) and this handle needs to be a global variable because you need to access this handle from functions like guiIs Clicked. Avoid overdrawing multiple GUI Items because this may result to unpredictable scenario. Always work with GUIRemoveAll(hwnd) to clean up the interface at the beginning and end to make sure your interface is cleaned up completely.

Other Features

MT4GUI Library can manage Buttons, Checkboxes, Lists, Labels, Text fields, Menus, Shortcuts, Links, Time, Remote-Time natively. You may check our Blog section for examples or switch to full documentation of all offered features.