MetaTrader MQL Course. Module 1: The MetaTrader Platform

The MetaTrader Platform

Congratulations! You’ve decided to find out what this MetaTrader craze is all about.  Let me give you my two cents.  Automated trading (with or without Expert Advisors) may not be for everyone, but if you are interested in finding out if it works for you, then MetaTrader is definitely the way to go.

The reason is because it’s free.  The platform, the data feed, even the demo accounts.  Yes, you need to invest your time, but if you are even remotely interested in investing, the time will be well spent.

So, why is such a powerful program offered for free?  Well, it’s free to you – the trader.  It’s not free to your broker (actually, it’s rather expensive).  Your broker makes money when you trade – the more you trade, the more money your broker makes.  (So automated trading must seem like a good idea for your broker, huh?)

If you have not installed MetaTrader yet, it can be downloaded from here: http://www.metaquotes.net/
(MetaQuotes is the company that created MetaTrader).
Just follow the instructions – MetaTrader installs just like any Windows program.

There are 3 major components of MetaTrader that I’ll cover today:

  • The Trading Platform
  • The MetaEditor
  • The StrategyTester

This is a screenshot of the Trading Platform

platformplatform

 The Market Watch window display the latest rates.  This window is not particularly important unless you are watching a pair for a specific price.  (We’ll learn later that it can be used to see if your Expert Advisor is alive.)

The Navigator window displays the available Accounts, Expert Advisors and Indicators.

The Terminal window displays status of your account and two tabs for monitoring Expert Advisors – Experts and Journal.

The MetaEditor is a text editor that is used to create Expert Advisors.  It can be launched from the Trading Platform either by going to Tools->MetaQuotes Language Editor or clicking the icon:

meicon

This is a screenshot of the MetaEditor:

metaeditor

The main window is used for editing your Expert Advisor.  The Navigator window is used for finding help.  The Toolbox window is used to see the results of building your Expert Advisor.

Let me say that after years of developing Expert Advisors (as well as writing other programs in many different languages) that the MetaEditor is an excellent tool:

  • The context sensitive help is very good.
  • It provides “intelli-sense” – this is the feature that attempts to finish words when you are typing.
  • It directs you to the exact line when you have a syntax error in your EA.

Actually, the MetaEditor is more than an editor.  It is what we programmers call an IDE – Integrated Developers Environment.  The MetaEditor builds an Expert Advisor by translating the text of your EA into an executable program that is interpreted by the MetaTrader Platform.

We will be using the MetaEditor extensively when building Expert Advisors and Custom Indicators.

The StrategyTester is used to simulate the performance of an Expert Advisor by feeding historical data into the EA and displaying the results.

The StrategyTester is opened by selecting View->Strategy Tester from the Trading Platform.

This is a screenshot of the MT StrategyTester.

tester

Now, I am not a huge fan of backtesting, but the StrategyTester is extremely useful for testing the logic of your EA.  When you know how to use it, it can literally increase your productivity by 1000%.  I’ll show how in a later segment.

Back to the MetaEditor

This is all I really wanted to cover today.  A basic overview of the platform with a brief description of the tools we’ll be using.

However, I want to add a small bit of Expert Advisor code to every segment, so next I’ll show how to create a very simple Expert Advisor.

In this exercise, we will open the MetaEditor, paste in some text, build an EA and then attach the EA to a price chart.

(Remember, the MetaEditor can be launched from the Trading Platform either by going to Tools->MetaQuotes Language Editor or clicking the icon:

meicon

 

Now, on to our MQL programming code exercise …

Open the MetaEditor and select File->New.  You’ll see these screens:
Select “Expert Advisor” and then click Next.

welcome

Enter a name, such as “SimpleEa” and click Finish.

wizard

This will create an Expert Advisor with three empty functions (Init() Start() and DeInit()).  Don’t worry about these functions for now.  Delete everything in the file (Edit->Select All and then Delete).  Paste the code from the below window into the MetaEditor and select the Compile button:

compile

 

MQL Code:

// simple EA

int start()
{
   Comment(“My first really simple Expert Advisor”);
   return(0);
}

Now open the Trading Platform and expand the Expert Advisors menu in the Navigator window. Find “Simple Ea” and double-click it. This will attach the EA to the selected price chart.  Select OK and your EA is running!  Watch the price chart to see what happens.