Single post

Learn to Write Forex Expert Advisors in MQL5 and Deal with Scripts


I’ve decided to start writing professional forex robot for mt5 in the language mql5. I’ve had to start from something, but I couldn’t find a reliable site or forum to ask advice from experienced people who could share their knowledge. So I’ve decided to start writing posts here and tell you what I’ve learned and what information’s settled in my memory. Dear readers, I ask you not to write useless comments in here and only ask thoughtful questions in case you couldn’t understand something.



MT5 Basics


MetaQuotes Language 5 (MQL5) is a built-in language of forex strategies developed by the company MetaQuotes Software Corp basing on its long-term experience in creation of Trade Information Platforms. This language allows writing your own good expert advisor that automate trading management and is ideal for realization of your own scalping forex strategies and other systems. Besides, you can use MQL5 to create your own technical indicators (Custom Indicators), scripts and libraries.


Expert advisor programming MQL5 includes many different functions necessary for analysis of current and past quotes, has built-in indicators and tools for management of trading positions and control over them.


In order to create the best expert advisor for forex, the text editor MetaEditor 5 is used. It highlights with different colors various constructions of the MQL5 programming language. It improves navigation through the code of the system. MetaQuotes Language Dictionary is the reference system for this programming language.


A short reference book contains different categorized functions, operations, reserved words and other language constructions and allows to learn the description of any element of the programming language.


MetaQuotes Language 5 software has different properties and purposes:



  • Forex expert advisor – it is an automated trading system that is tied to a certain chart. Forex robot operates at appearance of an event that it can process: initialization or deinitialization, appearance of new ticks, timer events, change of price glass, chart events and user events. Best Forex robot can not only work in the mode of information sharing about a possibility to perform a trade, bit also can automatically perform transactions on a trading account, sending them directly to the trading server. Robots are located in the folder “metatrader5_folder\MQL5\Experts”. Click here to find a lot of Forex Expert Advisors for MT4 and MT5 platforms.


  • User indicator is a best mt4 custom indicator independently created by a user in addition to integrated indicators. User indicators cannot trade automatically as well as the built-in ones. They serve only for realization of analytical functions. User free forex indicators are located in the folder “metatrader5_folder\MQL5\Indicators”.

  • Script is forex software intended for one-time performance of certain actions. Unlike experts, scripts do not process any events except launching event (to do it, a script must contain the OnStart function). Scripts are located in the folder “metatrader5_folder\MQL5\Scripts”.

  • Library is a library of user-defined function. It is designed to store and distribution of frequently used blocks of user programs. Libraries cannot be executed independently. Libraries are located in the folder “metatrader5_folder\MQL5\Libraries”.

  • Include file is a source code of frequently used blocks of user programs. Such files can be included to the source code of forex robots, scripts, user indicators and libraries on the compilation stage. The use of include files is more preferable than the use of libraries because of additional burden in case of calling library functions. The include file can be located in the same folder as the source file. In this case the directive #include with double quotation marks is used. Another location of include files is the folder “metatrader5_folder\MQL5\Include”. In this case the directive #include with brockets is used.

theme by teslathemes