⚡ Basic "Hello World Program" Execution in MQL4

 Basic "Hello World Program" Execution in MQL4 ⚡

Basic Hello World Program Execution in MQL4
Lesson 01 - Basic "Hello World Program" Execution in MQL4

You can start learning the MQL from its first version which is MQL4. which is similar to your academics computer science language C++. if you are not familiar with C++ then do not worry. I will cover each and every concept from scratch. 

What is the "Hello World Program" in MQL4?

When Computer Programmers start learning to new computer programming language they always start with the First Program which can give an illustration of the workflow of the selected programming language.

In the case of HTML, we simply create a "index.html" file and write some HTML code that generates output in Web Browser.

How to Open MQL4 Editor?

For the Programming in MQL4, You have to install MetaTrader4 Software on your Computer. After installation and opening the MetaTrader4 (MT4) Software. We can see the following option in Main Tool Bar. (See in Red Circle). This is an option for the Opening of MQL Editor.

Tip:- You can open MQL Editor by Pressing the "F4" Key on Keyboard also.

Basic "Hello World Program" Execution in MQL4 starting

Now you can bookmark this "MetaEditor.exe" on your Task Bar for easy access.

How to Create New Script in MQL4?

Open MetaEditor and click on "+New". after clicking you have to follow the screen. then choose "Script" from the available option. (For other Options like Expert Advisor, we will discuss in later tutorials.)

Create New Script in MetaEditor MQL

After Selecting the Ratio Button Script. Click on "Next". you will find the following Screen. Now put the Name of your Script. here I have used the script name as "MyFirstScript" and the Author name with a Link. You can set up as your requirements.

Create Script Hello World Program in MQL4

Click on "Finish". You will get the Coding Screen with some pre-written code as below.

Opening Script of MQL4 in MetaEditor

You can find your created Script in the "Navigator Panel" of the MetaEditor "Scripts" Section as above.

Focus on the Two braces symbols " { " and " } ". You can write your code between these braces.

How to Write "Hello World" in MQL4?

You can write Hello World Program in MQL4 in Three ways.

Method #1 - Using Alert Function

Alert("Hello World 1");
This Alert Function shows the output in PopBox. Which gives higher user attention. It is used for Important Events and Messages Only.

Method #2 - Using Print Function

Print("Hello World 2");
This Print Function shows the output in the Tab "Expert Advisor". which is basically the History Logs of executed code. It does not need any attention. you can check these messages when you want.

Method #3 - Using Comment Function

Comment("Hello World 3");
This Comment Function is used for showing results directly on Market Charts. It is used for printing price or values of Technical Indicators as well as Important calculations. which are needed on every Tick change of price.

I have created a combined example for all of these. Try to write code as below Example of "MyFirstScript.mq4".

Compile the Hello World Program in MQL4 with MetaEditor


After Writing these lines of Code. Click on "Compile".

Tip:- You can Compile MQL4 code by pressing the "F7" key from Keyboard also.

Once your code is successfully Compile. You can the "Errors" Description. which shows "0 Errors 0 Warnings" and Time used for Compilation of MQL Script. (see screenshot below)

No Errors in Compilation of MQL SCRIPT in MetaEditor.jpg


How to run MQL Script in MetaTrader Software?

Now, your MQL script is ready to "RUN" on Forex Market Chart. Now again Open MetaTrader Software and Goto "Navigator" window and move to the "Scripts" section.

Run the MQL Script in MetaTrader Software

Open your desired Currency or Commodity Chart on Drag and Drop the Script on Chart using your Mouse. here I have used "XAUUSD" = Gold, chart for running the "MyFirstScript". Which gives all of the three outputs as per the use of Alert, Print, and Comment functions.

Alert Function - Hello World Output


alert function hello world output of mql script in metatrader software

This Message PopUp will close, after clicking on the "OK" button. here you can see "Hello World 1". because I have passed  "Hello World 1" in the double quotation of marks.

Print Function - Hello World Output


print function hello world output of mql script in metatrader software.jpg

For getting the output of Print, you have to display the Terminal Window, which can be enabled by navigating to [Main Menu > View > Terminal] in MetaTrader Software.

Tip:- You can show the Terminal window by pressing "Ctrl + T" from the keyboard also.

After Opening the Terminal Window, see the Tab "Experts" as shown in the above screenshot. you can find your output message "Hello World 2" on XAUUSD Chart on M5 (5 Minute Chart) by the Script "MyFirstScript".

Comment Function - Hello World Output

Comment Function output is easily visible on Chart Screen. check the output as below "Hello World 3".

comment function hello world output of mql script in metatrader software.jpg

#Forex #Trading #MQL #Best #Knowledge #KHOPADI #latest

Summary

"Hello World Progam" in MQL4 can be implemented using 3 functions (Alert, Print, and Comment). You can use all of these as per your requirement and need. This is the very basic example for start learning the MQL Script which is used for Forex Trading automation.