Home | MQL4 Tutorial For Dummies | Blogs | EA Builder Blogs
Memberships Login | MQL4 Course | Community | Contact Us

Learn MQL4 coding Lesson 1


In my teaching style, I will teach you slowly and make sure you have strong understanding on the programming fundamental. Although I know that you will not need to be a MQL4 programming master, but at least you need to know how to do coding before jump into the MQL4 for coding. Spend a little bit more of times and read through this articles then you will know more on the fundamental of programming. 

In this article, you will learn

  • What is program flow
  • How a program flow
  • How MQL4 program flow is

In previous topic on introduction of MT4, it covers what is MQL4, and what can you do with MQL4. 

Before a newbie like you start to programming, there are few concepts that you must understand. That is the core of the programming. Programming is just like mathematic. It is very logic. If you are strong in mathematic, then programming is not a problem for you, however if you are weak in logic thinking, then you should think twice before continue on the journey of programming. 

First concept of programming is you should know the program flow. 

What is program flow? A program flow is the order of the program will be executed. There is a commander in all the programs. The commander will execute the task one by one. In an example, the commander in a country will be the president. President will give order what to do first, what to do next. So the program flow is the flow what will be executed first, what will be executed next. In MT4, the commander will be MT4 itself.  MT4 will give controls to the applications (EAs/Indicators/Scripts) to execute tasks

Then, next question, how the program will flow? A program flow is just like a water stream. Water will flow from a higher stream to lower stream. Same with programming, program flows from top task to bottom task. There is no way that water will flow from bottom stream to top stream, same like programming, there is no way that a program flow from bottom task and return back to the first task. In MQL4, the control will be passed over to the type of applications in different scenarios as below

  1. For an EA (Expert Advisor), the EA will be executed on every price changes / on tick. The control from the MT4 will be passed over to EA on each of the price changes. In MQL4, the price changes is called tick change. On each of the tick, then EA will be executed. This is the place all the criteria checking and the trade management will be taken in places. 
  2. For an Indicator, the indicator will also be executed on every price changes. Nevertheless, it is based on the chart event changes. Unlike EA, indicator couldn't trade. Indicator couldn't initiate/modify or close a trade. Indicator will just act as the existing indicator in the MT4 to show lines, objects to indicate on status of the chart of the symbol.
  3. For a script, the script will only be executed once. It is neither depend on the price nor the chart event change. The script will be executed instantly when the script is dragged into the chart/ or the script is executed by double click on the script in the MT4. (I will show how to execute an EA in another topic)

An example from the Hello World script above, you can see that I alert out 2 messages. First is "Hello World", second is "I can code". From the concept of water flow, "Hello World" will be executed first, then followed by "I can code". Remember, code always be executed from top to bottom. 

Let's look at the result of the script. 

As you can see from the popup screen in MT4, first message on "Hello World" is shown first, then second message "I can code" is shown next. Just take note that the popup screen appends new alert messages on the first line of popup dialog. Look at the timestamp, then it will be cleared. 

So, you have learned the program flow, you know how even know how to read the program now. You are about ready to start to do coding. 🙂 

Stay tune for up coming free tutorial. Thank you for reading and happy coding!

Leave a Reply

Your email address will not be published.