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

Introduction to MQL4 Programming

January 14, 2018 admin 0

Before you start any programming, you should know the origin of MQL4. What You’ll Learn In This Post What is MQL4 What MQL4 can do or cannot do What are the MQL4 applications that can build MQL4 or known as MetaQuotes Languages 4 is a script based command written by MetaQuotes Software corporation. Below are the feature of MQL4: It is to help forex trader to create own robot to manage the trade, which includes create trade, modifying trade, and as well as closing the trade. MQL4 embeds all the features that you can used in MT4, such as indicators (moving average, RSI (relative strength indicator), MACD) It can also helps to automatically update MT4 objects such as (fibonacci, trend line and more) It inherits all the behaviors and limitations from MT4: Account lot size limitation, buy stop and sell stop limitation from the price, and buy limit and sell limit limitation from the price. MQL4 is just a set of English words to form a series of commands. Imagine that, you learn a set of hand gesture commands to command your dogs to stand up. In MQL4, MQL4 are the special commands that are written in English, a set of MT4 commands to order MT4 to work accordingly. Sound simple right ? You just need to learn the commands to give order to MT4. MQL5 is a accessor of MQL4. Nevertheless many of the Forex broker is still using MQL4 and it is popular among the forex broker due to stability. MQL4 has a similar concept of C++ programming which is using object oriented. It is easy to be used and written as all the syntax and functions are well defined and documented in the MQL4 documentation. Having says that if you are a C++ programmer, then this will be a piece of cake for you. You can go ahead to program your EA. Nevertheless, for most of the Forex traders, you have no programming background. Before you start program, you might have fierce to learn how to write. But I can guarantee you, MQL4 is not that hard to learn. You do not need to learn all the functions / syntaxs / object oriented in MQL4 feature. From my 10 years programming experience, you just need to know the core of the programming and learn what you need to do. For example, if you want to learn how to analyse the different symbols of the markets, then you should learn the indicators. On the other hand, if you want to learn how to create your on bot for trading, then you should learn the skill to create an EA (Expert advisor). In short, if assume that there is 100% of the knowledge of MQL4, but you just need to learn 50% of it than you are fine to create your own robot. You do not need to learn all the technical terms. Just to be keep in mind of it. Learn what you need. Same set of MQL4 commands can be built for 3 main purposes: Expert Advisor or EA or Robot Expert Advisor is a sets of commands that will check on your trading criteria on each of the price changes. In MQL4, the price changes is called Tick changes. On each tick changes, then your trading criteria will be checked if it is matched and perform actions. So, your task is to rovide a set of criteria on the EA in order to perform actions on your trade, i.e. open a new trades. Indicator For trader who want to write indicators to draw own lines and objects on the chart to ease the analysis work. Then indicator is the feature you should look into. Take an example of moving average, if you want to create own line like moving average with your own mathematic algorithm, then you should write your own indicator. Then indicator could be shown in the chart. Script Script is a one time used command execution. Unlike EA / Expert advisor, the checking will not be repeated on each price changes. Script will only be executed once on appended to the chart. In the scenario where you want to check all of the symbol for each of the day and generate report, then you should use script to help you execute the tasks. Or if you have a script to help you close all of the active trade in your list without any hassle to close it one by one, especially during the critical time, then you should use script. So these are the introduction of the MQL4 for a MQL4 newbie. Have a look in other post to learn and understand more on MQL4. I have described this in video as well Post Views: 4,637

Learn MQL4 coding Lesson 1

January 14, 2018 admin 0

  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 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.  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. 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!