Trade Share CFDs for your favourite companies and 50+ U.S. stocks. Click here.
Refer a friend
Title Icon

Advanced

Identify hidden opportunities, master risk management,
and become an expert Forex trader.

The Beginner’s Guide to MQL5

MetaTrader, as a platform, has built-in functions that assist in technical analysis and trade management while also allowing traders to develop their own indicators and trading strategies. MQL5 is the integrated programming language used in MetaTrader for developing automatic trading strategies, creating custom technical indicators, and more. In our comprehensive guide, we will be understanding MQL5 in-depth.

What is MQL5?

MetaQuotes Language 5 (MQL5) is a programming language that helps traders with automated forex trading, creating their own indicators and testing trading strategies on the MetaTrader platform.

Features of MQL5

Price chart and indicator management

MQL5 allows traders to directly manage price charts. It also allows them to adjust colours, display custom symbols, move charts, and develop control panels. The trading robots (Expert Advisors) can be debugged on both price charts and multi-currency testers. The indicators can also be managed with 12 drawing styles and future predictive values through 512 buffers and direct calculations. You can also use more than one indicator to create a combined forex trading strategy through the program.

Graphic

Event-based Expert Advisors

MQL5 is event-driven and follows an event-based trading logic. It has the OnTick() symbol, which is used to handle events. You can use the tick flow (update of a currency pair’s prince) of any currency pair and receive entry or exit signals. The tick flow generates market activity signals, providing traders with ideal prices to enter or exit the market. The program executes within seconds, and you can move ahead to open another trade. Each trading operations data is handled with another handler called OnTradeTransaction(). So, you do not have to wait between trades to receive information. Hence, you are able to write trading algorithms efficiently by analysing different forex events.

Graphic

Multi-currency Expert Advisors

You can develop Expert Advisors with MQL5 that can trade on multiple symbols like EUR/USD, USD/GBP, and AUD/GBP. You can simultaneously test them on the strategy tester, which is a built-in tool that helps traders evaluate the efficiency of their EAs before they implement it in real-time. Traders can then debug their Expert Advisors in the price charts and use it with multiple currency pairs together to manage their portfolio having different types of currency pairs.

Graphic

MQL5 cloud network

The MQL5 cloud network enables fast trading optimisation and the creation of trading robots. It also unites remote MT5 agents. Then, it distributes all computation tasks among them to ensure each process is done quickly. With other processes of the programming language, traders are able to run thousands of tests to analyse and monitor the success rate of their strategies in a few hours. The more tests they are able to run with this feature, the faster they can judge if their trading strategy needs any changes or not.

MQL5 community

The MQL5 community helps forex traders connect and resolve each others’ queries. It also provides additional features like the WebTerminal, social trading platform, hosting services, trading application market, and more.

Graphic

CodeBase

CodeBase is the largest application library to exist for automatic trading. It consists of applications that can be used in MetaTrader 5 and MetaTrader 4 with the app’s source codes, expert advisors, scripts, indicators, and much more. The library is completely free, and anybody with access to MetaTrader can use the same. Traders can also post their personal developments here for others to use them.

Functions

MQL5 consists of hundreds of functions that can be used for generalised trading. These functions help in identifying market directions, deleting ticks from price history, creating databases, and much more. Each function on MQL5 serves a different purpose, from working with economic calendar events to creating technical indicators. Some of the widely used functions are:

  • FileReadString: Reads a file’s string from the current position of a trade
  • iAO to use the Awesome Oscillator
  • iBearsPower to understand the bear’s power in the market
  • MathSqrt to find a return’s square root
  • iCustom to develop a custom indicator

What does MQL5 help with?

Expert Advisors (EAs)

MQL5 enables traders to create several Expert Advisors (trading robots) that help in automating trades. Expert Advisors are written with the help of this language and use specific conditions to fit the trading needs of each trader.

Technical Indicators

Technical forex indicators are small program codes written in the language. These are displayed on the price chart or below them. They help in conducting technical analysis and placing an order accordingly. With the help of MQL5, all indicators can be managed together, and new custom indicators can also be created.

All orders, trades and positions

MQL5 also helps in placing ideal stop loss and take profit orders, managing overall trading orders, trades and positions in the forex market. The programming language helps modify existing positions and minimises the risk associated with each trade. It automates each function by rejecting invalid requests and processing the valid ones. The programming language, with the help of trading robots, identifies the best possible trade in the existing market, executes a trade and monitors the position to reap gains.

Different tabs available on MQL5

  • Journal tab: Displays all the events that occur during the strategy testing.
  • Agents tab: Helps in testing the strategies.
  • Graph tab: Displays the price chart graph after orders are sent to the Journal tab.
  • Inputs tab: Specifies all the input parameters that the Expert Advisors use.
  • Results tab: The tab is displayed after the strategy testing is completed, and it provides you with the summary of the test results.
  • Settings tab: Provides you with everything about the trade, like date, executing type, deposit, optimisation, and more.
  • Debug tab: Provides you with information regarding files, functions, types, lines and expressions to start the debugging process of the Expert Advisors.

What are the MQL5 data types available?

Each program needs to operate with data. Data types differ according to their purposes and help in different processes. Here is a list of the most important data types in MQL5 –

  • Int data type is 4 bytes (32 bits) in size and is used to access array components.
  • Char data type only takes a single byte of memory and helps in expressing in binary notation values, containing both negative and positive values.
  • Uchar integer data type’s size is also 1 byte but only provides positive values between 0 to 225.
  • Uint or unsigned integer data type takes 4 bytes in memory and helps traders express integer values 0 to 295.
  • Short data type is sized at 2 bytes and expressed in a range that is equal to 2 to the power of 16. It contains both positive and negative values.
  • Short or unsigned short data type is also sized at 2 bytes but only provides positive values.
  • The long data type is 8 bytes, giving both positive and negative values in size, whereas the ulong is also 8 bytes providing only positive values.
  • Bool data type helps in storing logical values in true or false forms and provides answers in the numerical representation of 0 and 1, respectively.
  • String data type helps in strong texts strings and takes the longest type to process as they take one of the biggest memory spaces.
  • Float data type provides values in fractions, and double data type is the same but only has twice the accuracy of float numbers.
  • Color data type stores information about colors and is 4 bytes in size.
  • Datetime data type stores the date and time in seconds about trades.

How to write and test an EA with MQL5?

1. Launch MQL5

Launch the MetaQuotes Language Editor 5 and press the ‘new’ button on the menu bar. An MQL5 Wizard Window will open. Select expert Advisor from this window and click ‘next’.

2. Give your EA a name

Enter the name of your EA in the name box that appears next. You can also provide the dialogue box with your email address or website link.

3. Change the parameters

When building your EA, you can customise the parameters per your trading preferences. You can also set multiple parameters to test which values give the best result. Add each parameter in the MQL Wizard dialogue box by clicking on the ‘add’ button. Add as many parameters as you may like.

4. Initialise the EA

Next, you can initialise your Expert Advisor by using an indicator function. You can add technical indicators like Moving Average or the Average Directional Index as parameters for the EA to react accordingly. These indicators are obtained by using functions specific to the MQL5 programming language.

5. De-initialise the EA

If you feel that your EA is not performing as per expectations, you can De-initialise it and remove it from your trading charts. All indicators released during the initialisation phase are de-initialised. However, this function can be skipped if your EA has started automating your trades successfully.

6. Check the number of bars on the chart

This step is possible by checking the EA’s ontick section. This checks if enough bars are present on the currency pair’s price chart. The EA can relax if there are 60 or fewer bars available on the chart until more bars are added so that the EA is able to provide accurate signals. If there are over 60 bars already present on the price chart, you can start using your EA to generate trading signals.

7. Debug the EA

The last step before testing the EA is to debug it. This will help identify code errors and improve it by checking how it performs line by line. Here is how you can debug the EA:

  • Open the tools bar on the Editor menu Bar and click on Options
  • Select the currency pair you are trading and its timeframe
  • Click on the ‘OK’ button
  • Insert a breakpoint to the code where you want the debugger to monitor the code’s performance
  • Press F5 and slick on the green button that appears on MetaEditor’s toolbar
  • Identify the error on the code, if any
  • Visit the trading terminal with the EA attached to the trading chart
  • Click ‘OK’ if all the errors are sorted or improve the code from where the debugger has noticed errors

8. Test the EA

The last step is to test the EA through the strategy tester. Press Ctrl+R to start the testing process. Thereafter, follow these steps to test your EA strategy:

  • Select the Expert Advisor that you want to test
  • Select the currency pair and timeframe for the test
  • Select a custom period
  • Set dates for the customer period, a minimum of 5
  • Select ‘normal’ in the execution tab
  • Select whatever deposit amount you want to use in USD
  • Set the optimisation option to disable, as you are only testing for now
  • Press the ‘start’ button

Start using MQL5 today

Start using MQL5 today to get hold of the impressive set of built-in indicators, custom tools, and functions that help you with automatic forex trading. You can build your own trading robots with MQL5 that seamlessly analyse quotes and trade forex on your behalf. Start forex trading in Australia with our platform to get access to MQL5’s trading platform, MT4 and MT5. Sign up for a live trading account or try a risk-free demo account.

Recommended Topics

  • What Are Bear and Bull Power Indicators?

    Bear and bull power indicators in forex measure the power of bears (sellers) and bulls (buyers) to identify ideal entry points.

  • How to Trade With The On Balance Volume Indicator

    The On Balance Volume (OBV) indicator analyses the forex price momentum to measure the market’s buying and selling pressure.

  • How to Use The Alligator Indicator in Forex Trading

    The Alligator indicator can identify market trends and determine ideal entry and exit points based on the trend’s strength.

  • How to Use Inside Bar Trading Strategy

    Inside bar trading offers ideal stop-loss positions and helps identify strong breakout levels.

  • What is the Martingale Trading Strategy in Forex?

    The Martingale trading strategy increases the possibility of winning a trade in the forex market.

  • How to Use The Forex Arbitrage Trading Strategy

    Forex arbitrage trading strategy allows you to profit from the difference in currency pair prices offered by different forex brokers.

  • How to Use DeMarker Indicator For Forex Trading

    Every trader needs to know precisely when to enter or exit a forex market.

  • How to Use The Accelerator Oscillator For Forex Trading

    The Accelerator Oscillator indicator helps detect different trading values that protect traders from entering bad trades.

  • A Forex Trader’s Guide to Awesome Oscillator

    When you understand market momentum, you can better identify market reversals.

  • What is Money Flow Index?

    The Money Flow Index can analyse the volume and price of currency pairs in the market.

  • What is The Ichimoku Kinko Hyo Indicator?

    The Ichimoku Kinko Hyo indicator provides traders with the market’s current momentum, direction and trend strength.

  • Top Pullback Trading Strategies

    Pullback trading strategies provide traders with ideal entry points to trade along with the existing trend.

  • What is High Wave Candlestick?

    The High Wave Candlestick pattern occurs in a highly fluctuating market and provides traders with entry and exit levels in the current trend.

  • What is the Parabolic SAR indicator?

    Identifying market trends becomes easier with the Parabolic SAR indicator as it provides the ideal entry and exit signals in strong trending markets.

  • What is Currency Correlation?

    Currency correlations help trade multiple currencies in the forex market by identifying the market trends of each currency pair.

  • Price Action Trading Strategy

    A Price Action Trading Strategy helps find ideal entry and exit points depending on expert opinions, news announcements, or technical indicators.

  • Average True Range

    Average True Range (ATR) helps in identifying how much a currency pair price has fluctuated. This, in turn, helps traders confirm price levels at which they can enter or exit the market and place stop-loss orders according to the market volatility.

  • Moving Average Crossover

    The Moving Average Crossover is a valuable tool to find the middle price-point of a trend in forex trading. When currency prices crossover their current moving averages, it helps traders identify the favorable buying or selling points for the currency.

  • What is the Bullish Engulfing Candlestick?

    Bullish Engulfing Candlesticks helps in identifying an uptrend reversal in the market. This candlestick pattern stands out because a trader does not need to wait until the entire pattern is completed to enter a trade.

  • How To Trade The Gartley Pattern

    The Gartley pattern helps identify price breakouts and signals where the currency pairs are headed. The pattern is also widely used in the forex market to determine strong support and resistance levels.

  • How to Trade Forex With NFP V-Shaped Reversal

    A Non Farm Payroll (NFP) V-shaped reversal refers to a sudden increase or decrease in the currency pair prices right after an NFP report is released.

  • Candlestick Patterns: Top Candlestick Charts Every Trader Should Know

    Candlestick patterns depict the price movement of assets in a graphical manner. Candlestick patterns also enable traders to predict market behaviour.

  • What is the Evening Star Candlestick Pattern?

    Evening Star Candlestick Patterns help traders identify ideal exit levels in the forex market by signalling a slowed upward momentum and strengthened downward momentum.

  • How to Use Ichimoku Cloud in Forex?

    The Ichimoku Cloud provides a clear market trend direction to the traders and helps them make market decisions accordingly.

  • Pennants Pattern: How to trade bearish and bullish pennants

    Pennant Patterns work as a continuation signal in the forex market and help identify the ideal entry and exit price points

  • How to Trade Forex With Renko Charts

    Renko Chart is a technical indicator that provides strong market trend directions by filtering out minor price movements

  • What are Ascending and Descending Triangle Patterns?

    The Ascending and Descending Triangle Patterns confirm continued trends in the forex market.

  • How to Identify Cup and Handle Pattern in Forex Trading

    The Cup and Handle Pattern is a technical price chart that forms the shape of a Cup and a Handle, which indicates a bullish reversal signal.

  • What is the Head and Shoulders pattern?

    The Head and Shoulders pattern is a trend reversal indicator that predicts bullish to bearish and bearish to bullish reversals in the forex market.

  • What is the Hammer Candlestick Pattern?

    Hammer Candlesticks enable traders to identify potential market reversal points, determine the ideal time to enter the market and place buy or sell orders accordingly.

  • What is The Opening Range Breakout Strategy

    The Opening Range Breakout (ORB) Strategy involves taking forex positions when the currency pair prices break below or above the previous day's high or low

  • Morning Star Indicator

    The Morning Star Indicator helps identify strong trend reversals in the forex market and enables you to take trade position entry decisions accordingly.

  • How Does Stochastic Indicator Work in Forex Trading?

    Stochastic Indicator helps traders identify overbought and oversold market conditions that substantially lead to market reversals.

  • Favourite Fib Fibonacci Retracement

    Fibonacci retracement strategies help traders identify the market's support and resistance levels, trend reversal points, and entry and exit decisions.

  • Heikin Ashi Candlestick Pattern

    The Heikin Ashi Candlestick pattern is almost the same as the traditional candlesticks, with one big difference—the former is an averaged out version of the latter.

  • Multiple Time Frame Analysis in Forex

    By monitoring different currency pairs in different time frames, you can make your Forex trades more successful and profitable.

  • What are Bollinger Bands?

    The Bollinger bands can help identify overbought and oversold market conditions, protecting you against placing any orders that could lead to losses.

  • Andrew's Pitchfork Trading Strategy

    Andrew's Pitchfork is a Forex trading strategy that can predict protracted market swings and help you in identifying potential market trends that can indicate potential exit and entry points.

  • Fibonacci Retracement

    Fibonacci retracements are one of the most popular methods for predicting currency prices in the Forex market. Predicting upward or downward market movement can help traders with accurate price analysis for exiting or entering the market.

  • Trading in Volatile Markets

    Forex volatility is the measure of how frequently a currency's value changes. A currency either has high volatility or low volatility depending on how much its value deviates from its average value.

  • The ABCD pattern

    One of the most classic chart patterns, the Forex ABCD pattern represents the perfect harmony between price and time.

  • The Bearish Gartley Pattern

    The Bearish Gartley pattern was introduced in 1935, by H.M. Gartley in his book, “Profits in the Stock Market”. The pattern helps Forex traders in identifying higher probabilities of selling opportunities.

  • The Bullish 3 Drive pattern

    The Bullish Three Drive pattern in Forex trading is a rare pattern that gives traders information about the Forex market's potential at its most Bearish point, and in turn, suggests probabilities for a market reversal.

  • What is the MACD Indicator?

    The Moving Average Convergence Divergence (MACD) indicator helps traders quickly identify short-term trend directions and reversals in the forex markets. You can use the MACD indicator to determine a currency pair price trend's severity and measure its price's momentum and even identify the bearish and bullish movements in the currency pair prices.

Guide to Forex
Trading indicators.

Enter your details to get a copy of our
free eBook

Thank you, please check your inbox for your ebook.

Ads BG

Start a risk free
demo account

News & Analysis

Catch up on what you might
have missed in the market.

Runner graphic

Ready to trade at
Blueberry Markets?

Your best trading experience
is a click away