This 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.
- With AUD/USD chart open double click on desired indicator.
- Enter parameter settings and execute.

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:
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.
Popular Posts
-
My New Favourite Poker Game – Limit 2-7 Triple Draw Lowball
October 13, 2009 -
eSignal OnDemand - Trading Software Review – Is it worth the money?
October 28, 2009 -
Moving to Mac: You Can Have it All
February 22, 2010
Related Posts
-
Forex From Scratch FREE eBook
August 13, 2010
-
Building an Automated FOREX System: Writing the Pseudo Code
April 12, 2010
-
Setting up The Perfect Python Development Environment
March 29, 2010
Do you have something to say?
Trade to Win
Trading Wisdom
One market paradigm that I take exception to is : Buy low and sell high. I believe far more money is made by buying high and selling at even higher prices. That means buying stocks that have already had good moves and have high relative strength – that is, stocks in demand by other investors. I would much rather invest in a stock that’s increasing in price and take the risk that it may begin to decline than invest in a stock that’s already in a decline and try to guess when it will turn around.
— Richard Driehaus
Recent News
Archives
- August 2010
- July 2010
- June 2010
- April 2010
- March 2010
- February 2010
- November 2009
- October 2009
- September 2009
- July 2009
- June 2009
- April 2009
- February 2009
- January 2009
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007


Great comment about investments