Building an Automated FOREX System: Expert Advisors & Indicators

IndThis is article number two in our tutorial series Building an Automated Currency Trading System from Scratch. If you have not read the introduction to this tutorial series I recommend you read building an ATS before reading this article.

MetaTrader 4

The current version that is most widely used and supported is MetaTrader 4 however beta versions of MetaTrader 5 are currently in testing. In order to build an automated trading system using MetaTrader 4 we will need to write a program that will run inside MetaTrader. There are three types of programs that run inside MetaTrader, these are Custom Indicators, Expert Advisors and Scripts. The screen shot on the right shows the built in indicators that ship with MetaTrader.

MetaTrader- MetaQuotes Language

Custom Indicators, Expert Advisors and scripts are all written in a programming language called MetaQuotes Language, often abbreviated MQL.  Although all three application types are written in MQL there are slight differences between program types.

MetaTrader- Indicators and Custom Indicators

Custom indicators are written in MQL the client terminal will execute the indicator every time a tick is received. The main use of indicators is to graphically display some user defined or built in data relationship. The most common use for indicators is for Technical Analysis. Below are some screenshots which show a built-in indicator being applied to the daily AUD/USD currency chart.

  1. With AUD/USD chart open double click on desired indicator.
  2. Enter parameter settings and execute.

Indicator Setting MetaTrader

MACD Indicator

MetaTrader- Expert Advisors

An Expert Advisor or EA for short share similar properties to Indicators. Expert Advisors or EA’s are written in MQL and are executed on tick data. Expert Advisors or EA’s have trade logic written into them. Basically an EA does everything an indicator can do, however an EA will also open, close and modify trades programmatically. To attach an EA to a currency pair the process is exactly the same as it is for an indicator. There are two sample EA’s that ship with MetaTrader 4 these are the MACD Sample and Moving Average.

MetaTrader- Scripts

Scripts are the final type of application that are available in MetaTrader. A script is designed to be executed only once. Scripts are usually used to automate client side non-trading actions, like modifying data. They can however be used to perform simple trade logic tasks.

MetaTrader – MetaEditor

All the code we write for our automated trading system will be done MetaTrader’s Integrated Development Environment called MetaEditor. MetaEditor allows you to store and manage source code for all projects in an easy to use way. If you are used to Visual Studio or X-Code IDE’s then you will be disappointed with the functionality of MetaEditor. MedEditor does offer syntax highlighting and code completion which is very handy. There is also a built in on-line library that covers most topics. Below is a screenshot of the IDE:

MetaEditor

To open MetaEditor from MetaTrader simply press F4 or from the menu bar:

Tools –> MetaQuotes Language Editor

Home Work

Before next article make sure you understand the three different program types that are used in MetaTrader. Also try attaching and using some of the built in indicators in MetaTrader. Before moving on I would also recommend downloading the MQL4 book from MetaQuotes. This is a free book that covers the basics of programming in MQL and in later articles I will assume you are up to speed with the concepts presented in the book.

In the next article we will discuss designing a simple trading strategy and pseudo code.

About the author

Mark - Is a 28 year old form Australia. He has a Bachelor in Economics and a Major in CS. He is currently working towards his CFP. His interests include algorithmic trading systems, artificial intelligence, game theory and poker.

2 Responses to "Building an Automated FOREX System: Expert Advisors & Indicators"

Trackbacks/Pingbacks

Do you have something to say?

Your email is never published nor shared.
Required fields are marked *