MQL4 Program Types

Now that you have a better understanding about what MQL is we can introduce the main categories of programs that you can create with this powerful language. If you don’t know what MQL is I would suggest to read the article What is MQL4 before proceeding with this one.

With MQL it is possible to create different types of programs and each type is different from the others. Also interesting that one type of program can be used by the other types in different ways, meaning for example, an indicator can be used in a Script or in an Expert Advisor, but we will see this in more details in the individual types.

As mentioned before the main types of programs that you can find and write:

  • Include Files
  • Libraries
  • Scripts
  • Indicators
  • Expert Advisors



Include Files

Include Files are text source files containing code that you want to use in other programs. Include Files have a MQH extension and are stored in the MQL4_Client_Terminal_Folder\MQL\Include or in the same folder as the source files that are using the included one. Include Files cannot run by themselves, they can only be included in other types of programs. It is worth to expand this concenpt in case you are not familiar with writing code. Assume that you have strict rules of risk management, all your orders will have a position size calculated following your risk management rules. What you can do is create a function to calculate your position size and save it in an Include File, you can then include this file in a script or expert advisor and use the included function without having to write the code again. Basically the advantage of Include Files is to keep the code clean and the ability to re-use portions of code.


Libraries have the same purpose of Include Files but they have MQ4 extension and they are saved in the MQL4_Client_Terminal_Folder\MQL4\Libraries. As the Include Files, Libraries cannot run, they can only being included in other types of files.


Scripts are programs that once run execute a specific action once. The source file of a script has a MQ4 extension while the compiled executable version has a EX4 extension, scripts are saved in the MQL4_Client_Terminal_Folder\MQL4\Scripts folder. Scripts and Expert Advisors are very similar, they can both execute actions, however, there is a fundamental difference between the two: Scripts execute the task only once and then they exit, Expert Advisors repeat the action. Scripts can perform a simple action or more complex tasks, some examples can be:

  • Open an order with a default or calculated position size and/or stop loss and take profit
  • Create a report and save to file
  • Send a report through email
  • Close all open orders immediately
  • Calculate some values and returning the result

Scripts can use default and custom indicators and can also include Libraries and Include Files, but remember, they only run once when executed. We will have a further look to scripts in the Scripts category.


Indicators are graphical representations of prices and/or manipulation of prices. To provide an example think about a Simple Moving Average, that is probably the most common and popular indicator and it represents the average price over a period of time. The source files of indicators have a MQ4 extension while the compiled executable versions for MetaTrader 4 have an EX4 extension. Indicators files are saved in the MQL4_Client_Terminal_Folder\MQL4\Indicators. MetaTrader 4 comes with several indicators already but sometimes they are not enough. The web is full of enhanced indicators which may suit better your trading style and if that is still not what you are looking for, with MQL4 you can create your custom indicator. Again, an indicator is a graphical representations of prices and/or manipulation of prices, you attach it to a chart and it will show you the information it is programmed to show.

Some examples of standard indicators are:

  • Moving Average (MA)
  • Average True Range (ATR)
  • Stochastic Oscillator (Stoch)

Custom indicators can be enhanced versions of existing ones or completely new ones, we will see examples of custom indicators and how to edit and create new in the Indicators section.


Expert Advisors

Expert Advisors are probably the most powerful tool you can develop with MQL4, they are programs that you run/attach to a chart and they continue running until you manually stop them. To understand how an Expert Advisor works you must understand the concept of tick, we will talk about Tick in another article but for now I will just anticipate that the Tick is what triggers the action of the Expert Advisor. Having an Expert Advisor running allows MetaTrader to continuously monitor prices and indicators and perform specific programmed actions when conditions are verified. Expert Advisors source files have a MQ4 extension while executable compiled versions have a EX4 extension, the folder where these files are saved is MQL4_Client_Terminal_Folder\MQL4\Experts. Expert Advisors are know in the trading arena with different names and even if there are minor differences in their meanings they mostly refer to tools used to automate the trading activities. Expert Advisors are also known as Black Boxes, Trading Robots, Bots. You can find Expert Advisors on the web, for free and commercial products, however, always be careful as there are many scams around, in alternative you can create your own robot, which is what I recommend. Expert Advisors can be very versatile, some examples of actions that they can perform are:

  • Monitor prices and/or indicators and place or close orders when prices or indicators reach a set threshold
  • Send alerts or notifications via email or on screen when some conditions are verified
  • Move stop loss or take profit level automatically, trailing stop
  • Send automatic reports
  • Perform an action at a scheduled time

As you can see the Expert Advisors can be very useful and you will see other examples and advantages in the Expert Advisors section.


You should now have a better idea about the types of programs you can find, and create, with MQL and it is probably time for you to meet MetaEditor.

We use cookies to ensure that we give you the best experience on our website.