Showing posts with label MQL5. Show all posts
Showing posts with label MQL5. Show all posts

MetaTrader 5 (MT5) is not only renowned for its comprehensive trading features but also for its powerful programming language, MQL5. MQL5 opens up a world of possibilities for traders and developers, allowing them to create custom indicators, expert advisors, and scripts to automate and optimize trading strategies. In this article, we will explore the key features and advantages of MQL5, and how it has revolutionized automated trading within the MetaTrader 5 platform.



Understanding MQL5

MQL5 is a high-level programming language specifically designed for developing trading strategies and custom technical indicators in MetaTrader 5. It combines the flexibility of C++ syntax with an intuitive and user-friendly interface, making it accessible to traders with various levels of programming expertise. MQL5 allows traders to automate their trading activities, execute complex calculations, and access real-time market data.


Key Features and Benefits

1. Easy-to-Use Syntax: MQL5 features a syntax that is similar to C++, making it easier for programmers with a background in C-style languages to transition into algorithmic trading. Additionally, the MQL5 Wizard provides a graphical interface for creating simple scripts and expert advisors without the need for extensive programming knowledge.

2. Extensive Library of Functions: MQL5 provides a comprehensive library of built-in functions and trading operations. Traders can leverage these functions to perform technical analysis, execute trades, manage positions, and access market data. The library covers a wide range of functionalities, enabling developers to create complex and sophisticated trading systems.

3. High-Speed Execution: MQL5 programs are compiled into machine code, which allows for efficient and high-speed execution. This is particularly important for algorithmic trading strategies that require quick response times to take advantage of market opportunities.

4. Integration with MetaTrader 5: MQL5 seamlessly integrates with the MetaTrader 5 platform, providing access to real-time market data, historical prices, and account information. Traders can easily implement their strategies and indicators within the MetaTrader 5 environment, ensuring a smooth and efficient trading experience.

5. Advanced Testing and Optimization: MQL5 offers a robust backtesting framework that allows traders to assess the performance of their trading strategies using historical data. The built-in optimization tools enable traders to fine-tune their strategies by testing different parameter combinations and selecting the most optimal settings.

6. Market of Trading Robots and Indicators: The MQL5 Market is a built-in marketplace within MetaTrader 5 where developers can sell their trading robots, indicators, and other MQL5 programs. Traders can browse and purchase ready-made solutions, saving time and effort in developing their own strategies from scratch.

7. Community Support and Collaboration: MQL5 boasts a large and active community of traders and developers who share their knowledge, code snippets, and expertise. Traders can seek help, discuss ideas, and collaborate with fellow programmers, fostering a vibrant environment for learning and innovation.

8. Security and Reliability: MQL5 programs undergo a rigorous security review by the MetaTrader 5 platform, ensuring the integrity and safety of the trading environment. Traders can be confident in the reliability and stability of their automated trading systems.


Why should you learn MQL5?

MQL5 has revolutionized the world of automated trading within the MetaTrader 5 platform. With its powerful features, user-friendly syntax, and seamless integration with MetaTrader 5, MQL5 empowers traders to automate their trading strategies, optimize performance, and unlock new possibilities in the financial markets. Whether you are a seasoned programmer or a trader with minimal coding experience, MQL5 provides a flexible and efficient environment to transform trading ideas into reality.

As the demand for automated trading continues to grow, MQL5 remains at the forefront of innovation, providing traders with the tools and capabilities necessary to stay competitive in the ever-evolving financial markets. With its extensive library of functions, advanced testing capabilities, and a vibrant community of traders and developers, MQL5 is a game-changer for traders seeking to harness the power of automation in their trading journey.

Start here: MQL5 Documentation: https://www.mql5.com/en/docs/basis

mql5 magazine logo
Check out this great blog about MQL programming and Metatrader 5 related stuff: http://mqlmagazine.com The authors of the blog are Bogdan Caramalac and Bogdan Baltatu, professional traders and MQL programmers from Romania. The blog has many great articles, for example: Tick events in MQL5: complicated for now, but functional or Quoting – A new activity in MT5

About their blog:

MQLmagazine.com is a web magazine for MetaTrader users and MQL programmers, covering automated trading in forex, futures, options and equities.

Metatrader 5 – A Probably New Beginning For Everything

This was the title of my last post in my former blog on the vamist.ro website – the romanian forex community. At that time I was announcing my decision to move my blog on a brand new domain – my own. However, things changed and there had come the decision to write a magazine. But what kind of magazine ? Well, there are plenty magazines for traders. Take a look at the ones better known – CurrencyTrader , Futures & Options Trader… They target most of the time the strategical type of trader. The one that takes long term trades that span on months. This is why most of their analysis are floating around market forecasts. Of course, around these, different platform commercials and explanations of “forex” terms.

The retail forex market is around for some good years. In the so-called “western world”, these markets became known and called for retail traders right from beginning. But here, in Romania, where the authors are located, forex is still not too much known. However, we will not make a forex magazine. As I said, forex was what was offered to beginners at that time.

Things have started to change a bit a few years ago, when forward steps have been made by several brokerages, that started to offer futures and equities under MetaQuotes’ most acclaimed platform, Metatrader 4. But it wasn’t the time of a revolution in retail trading. Because Metatrader 4 was not designed – although it is the best retail trading platform – to trade the manner professional traders think and do it. Therefore, several trading strategies that were known to professional traders and , in general, to the hedge fund world, have remain hidden from the sight of retail traders.

Even more, brokerages commercials and forums accentuated the traders indoctrination that forex was the ultimate market that could have been traded. Lots of trading strategies and markets were hidden : pair trading strategies, quoting, forex arbitrage (although it was tackled at that time by a few, including myself) , forex / futures arbitrage, commodities arbitrage, and finally option strategies. Option strategies still are, at this time, the realm of derivatives quants. Even professional option traders don’t trade the way they might think – because either the platforms can’t do it and the NFA regulations restrict it. Here are some facts about trading platforms and regulations:

- most of them do not have a backtesting module;
- most of them do not support even exchange traded options, not speaking about exotics;
- most of them do not offer automation for options, and that including the well-known TradeStation and OptionStation;
- option stations may not support any other assets – example RAN Order and IKON.
- the ones that have a backtesting module may not backtest multiple assets;
- data feed is dependant on either broker or data provider; so you may have, or not, what you desire to trade;
- they might offer their own scripting language or API ; professional platforms might offer only FIX specification and leave automation on the hands of extremely skilled C++ programmers;
- under NFA regulations you cannot trade in a forex account anything else besides forex, gold and silver. Anything else, including forex options or real futures, trade in a separate account;
- under NFA regulations you cannot trade CFDs (broker manufactured assets that mimic real market, being tailored to small investors);
- under NFA regulations you can trade futures, equities, and options in the same account;
- and finally, under NFA regulations, you cannot hedge – that is, you cannot be long and short at the same time on an instrument ; even more, positions open and close in a FIFO manner.

Unfortunately, Metatrader 4 didn’t score too much either ; a limited platform, extremely latent , which can’t backtest anything but strategies trading one asset and with no implementation of options. As a result, anything quite constructive that could have been built in theoretical conditions (i.e. textbook strategies) could not be backtested or not even implemented at all.

But with the emergence of the new MetaQuotes’ flagship platform, Metatrader 5, things have started to change. At the time this article is being written, Metatrader 5 is in open beta. The “Strategy Tester” module (which is well known by some of our readers and will be also presented in future articles) is not present in the platform. It is our belief that the Strategy Tester will allow development of multiasset strategies. Multiasset backtesting is needed in a lot of situations. I might even say that all successful trading is multiasset trading. You might ask why. And the answer is simple. All [successful] trading is a form of arbitrage. Some will argue and say that very good trading systems don’t arbitrage – but when you look at a sheet with trades and see a good percentage of profitable trades that are not offset by bad trades, somehow the system knew to buy something cheap and sell something expensive, so it does nothing else than a price-value arbitrage. But one-asset markets are just too random for the unexperienced trader to handle. After all, what is of value is the multiasset approach, because markets can’t be too efficient overall. Correlations are broken, parity relations are broken, add to this the magic of options, and look at the big picture : markets become full of opportunities! Now don’t ask why they got into the crysis : they had too much money, way too much money in order to make enough using opportunities. After all, we’re not interested in universal strategies that apply to everyone. But in strategies that apply to US, THE SMALL GUYS.

So, given that the new Metatrader 5 comes with new features, like multiasset backtester, option trading and event-based programming, we decided it was time for a magazine for all things MetaTrader. Of course, with the accent on MQL programming. The magazine will be addressed to all categories of MetaTrader users: absolute beginners that never heard of trading and are making the first steps in the world of markets, MetaTrader traders that use the terminal , and finally all categories of MQL programmers – task specific programming and also complex strategies design and programming.
Source: Mqlmagazine.com

Some time ago, Paul (phampton) wrote on his blog about the creation of extended documentation for the MQL5 code using some free tools like Doxygen and HTML Help. This extended documentation in the form of a a compiled HTML help file, includes class hierarchies and methods for all the code distributed under the MQL5 folder, like the MQL 5 indicators or the MQH include files.

Each MQL5 file has a reference list with all functions and variables and everything is cross-linked. There is also an alphabetical index for it. This way it can help you a lot to learn the new Metatrader 5 MQL5 programming language. You can also add custom made indicators and other MQL5 files to the documentation. Below are some screenshots illustrating the documentation file:

mql5 metatrader 5 extended documentation

mql5 metatrader 5 extended documentation

mql5 metatrader 5 extended documentation

mql5 metatrader 5 extended documentation

Paul has already compiled the documentation file, and you can download it here.
If you want to learn how you can create such a documentation file yourself, read the post on Paul's Blog.

mql5 website
The website mql5.com is now online! ;) The forum , mql5 documentation and articles section are already working, but the code base is still in development. Great news for all MQL5 developers: a MQL5 book is planned and it will be written by Sergey Kovalyov, author of the MQL4 book.

Now that the MQL5 documentation is online, you don't need a local version of the MQL5 help. The MQL5 language continues developing and the official documentation will be extended and improved, so the online version will contain always the last updates. So if you plan to learn MQL5, the mql5 documentation is the best place to start!

All forum accounts were moved from the MQL4 website, so you can use your existing login, you should only fill your profile and upload an avatar if you use one.

Some information about the migration from MQL4 to MQL5:

MQL5 is the development of its predecessor - the MQL4 language, in which numerous indicators, scripts, and Expert Advisors were written. Despite the fact that the new programming language is maximally compatible with the previous-generation language, there are still some differences between these languages. And when transferring programs these differences should be noted.

Information intended to facilitate the adaptation of codes to the new MQL5 language for programmers who know MQL4:

First it should be noted:

• The new language does not contain functions start(), init() and deinit();
• The number of indicator buffers is not limited;
• dll is downloaded immediately after downloading an Expert Advisor (or any other mql5 program);
• Check of logical conditions is shortened;
• When limits of an array are exceeded, the current performance is terminated (critically - with the output of an errors);
• Precedence of operators like in C + +;
• The language offers the implicit type cast (even from string to a number);
• Local variables are not initialized automatically (except for strings);
• Common local arrays are automatically deleted.

Special Functions init, start and deinit
The MQL4 language contained only three predefined functions that could be used in the indicator, script or Expert Advisor (not taking into account the include files *.mqh and library files). In MQL5 there are no such functions, but there are their analogues. The table shows the approximate correspondence of functions.

metatrader 5 - mql5

Functions OnInit and OnDeinit perform the same role as init and deinit in MQL4 - they are designed to locate the code, which must be performed during initialization and deinitialization of mql5 programs. You can either just rename these functions accordingly, or leave them as they are, but add calls of these functions in corresponding places. The start function is replaced by OnStart only in scripts. In Expert Advisors and indicators it should be renamed to OnTick and OnCalculate, respectively.

Example:

void OnInit()
{
//--- Functions is called to initialize
init();
}
void OnDeinit(const int reason)
{
//--- Call the function with deinitialization
deinit();
//---
}
If the indicator or script code does not contain the main function, or the function name differs from the required one, the call of this function is not performed. It means, if the source code of a script doesn't contain OnStart, such a code will be compiled as an Expert Advisor. If an indicator code doesn't contain the OnCalculate function, the compilation of such an indicator is impossible.

Predefined Variables
In MQL5 there are no such predefined variables as Ask, Bid, Bars. Variables Point and Digits have a slightly different spelling.

metatrader 5 - mql5

Access to Timeseries
In MQL5 there are no such predefined timeseries as Open [], High [], Low [], Close [], Volume [] and Time []. The necessary depth of a timeseries can now be set using corresponding functions to access timeseries.

Expert Advisors
Expert Advisors in MQL5 do not require the obligatory presence of the function for handling the events of a new tick receipt - OnTick, as it was in MQL4 (the start function in MQL4 is executed when you receive a new tick), because in MQL5 Expert Advisors can contain pre-defined handler functions are several types of events:

• OnTick – receipt of a new tick;
• OnTimer – timer event;
• OnChartEvent – events of input from the keyboard and mouse, events of a graphic object moving, event of a text editing completion in the entry field of the LabelEdit object;
• OnBookEvent – event of Depth of Market status change.

Custom Indicators

In MQL4, the number of indicator buffers is limited and can't exceed 8. In MQL5 there are no such limitations, but it should be remembered that each indicator buffer requires allocation of a certain part of memory for its location in the terminal, so the new possibility should not be abused.
MQL4 offered only 6 types of custom indicator plotting; while MQL5 now offers 18 drawing styles. The names of drawing types haven't changed, but the ideology of the graphical representation of indicators has changed significantly.
The direction of indexing in indicator buffers also differs. By default, in MQL5 all the indicator buffers have the behavior of common arrays, i.e. 0 indexed element is the oldest one in the history, and as the index increases, we move from the oldest data to the most recent ones.
The only function for working with custom indicators that was preserved from MQL4 is SetIndexBuffer. But its call has changed; now you should specify type of data to be stored in an array, linked to the indicator buffer.
Properties of custom indicators also have changed and expanded. New functions for accessing timeseries have been added, so the total calculation algorithm must be reconsidered.

Graphical Objects
The number of graphical objects in has increased significantly MQL5. But now there is a limitation - functions for working with graphical objects can't be used in custom indicators.
Besides, graphical objects can now be positioned in time with the accuracy of a second in a chart of any timeframe - now object anchor points are not rounded off to the bar opening time in the current price chart.
For objects Arrow, Text and Label now way of binding can be indicated, and for Label, Button, Chart, Bitmap Label and Edit chart corner, to which the object is anchored, can be set.

Source: MQL5 Reference

metatrader 5


A new article about custom indicators in Metatrader 5 was posted today on the mql4.com website. It explains the MQL5 indicators, their structure, drawing, types and their programming details, comparing to MQL4. Also, 7 new custom indicators were presented with the article.

Read

A script which converts MQL 4 code to MQL 5 code was developed by Keiji and Circlesquares on the MQL4 forum.

First, download the following files and place them in your Metatrader 4 / experts / include folder

- mt4accountinfo.mqh
- mt4string.mqh
- mt4datetime.mqh
- mt4objects_1.mqh ( updated version ), see post below.
- mt4timeseries_2.mqh ( updated version ), see post below.

Rewrite MQL 4 to MQL 5 Script

Now, download the latest version of the rewrite script and place it in your Metatrader 4 / experts / scripts folder:

- mq4to5rewrite_sample_v4_2.mq4

After that you will need to place a mql4 indicator, script or ea which you want to convert to MQL 5 in your Metatrader 4 / experts / files folder. Now open Metatrader 4 and run the script. As you can see you must first provide the name (without extension) of your mq4 file and select if it is an indicator (0), EA (2) or script (3) file.

Rewrite MQL 4 to MQL 5 Script

In my case i'm rewritting a MQL4 indicator named ang_DCT:

Rewrite MQL 4 to MQL 5 Script

Now hit the "OK" button and if everything is done, the following message will appear:

Rewrite MQL 4 to MQL 5 Script

After that go to your Metatrader 4 / experts / files folder and you will find the converted mq5 file there:

Rewrite MQL 4 to MQL 5 Script

Now open this file with Metaeditor 5 in compile it:

Rewrite MQL 4 to MQL 5 Script

Try to fix the errors with the MQL4 to MQL5 Porting Table and the last version of the translated MQL5 user guide.

Fai has posted today a handy table with a comparison of the MQL4 and MQL5 functions ( MQL4 to MQL5 Porting Table ). It will help a lot with learning of the new MQL5 language.

MQL4 to MQL5 Porting Table

Download

See also: MQL 5 User Guide

metatrader 5 user guide

Here are the user guides for MetaTrader 5, MetaEditor 5 and MQL5. You can find there many useful information regarding all features and possibilities of the new MT5 Platform. Topics like user interface, working with charts, analytics, market watch and trading, etc. are covered. It is now the best source of documentation to read. ;)

The MQL 5 User guide is not yet available in English so it was translated via Google Translate.

You can find the MetaTrader 5 and MetaEditor 5 user guides in your \MetaTrader 5\Help\ folder. But if you didn't install the MT5 beta, you can download the user guides below.

Download:

MQL 5 User Guide

Metatrader 5 Terminal User Guide

Metaeditor 5 User Guide



The main difference between MQL4 and MQL5 is the appearance of the object oriented programming. So you can start learning MQL4 now, because:

1. If You know MQL4 the only thing in MQL5 to change in your programs will be names of a couple of start() init() deinit() functions;
2. If you know MQL4 the transition to mql5 will be smooth;
3. If you know mql5 you will know C language as well because they are VERY close;
4. Due to providing structures and other improvements in MQL5, there will be a LOT of new possibilities to merge MQL5 with any database, math, statistical packages etc.

Promised that MQL5 will be very similar to classic C / C++, except:

1. Pointers;
2. Goto operator;
3. Anonymous enumeration;
4. Address arithmetic and class inheritance;
5. Some exotic staff from so-called "object-oriented programming": classes constructors do not have parameters, no multiply inheritance etc.

Operators overload and ternary operation ( expr ? op1 : op2; ) will probably be included later.

So MQL5 will be VERY close to C. The greatest improvement are structures. If you already know some basic MQL4 programming and want to learn C++, you can start with books like C++ for Dummies. You can also use C++ BNF description.

metatrader 5

There is one unpleasant limitation in MQL5 and Metatrader 5: Objects cannot be created from indicators. I mean fubctions like ObjectCreate or ObjectName are now not possible to apply to indicators. According to , this was made intentionally to speed up the performance of indicators. So graphical objects are now only available in EA's.

Some time ago there was a discussion on the mql4 forums about this limitation and how to avoid it, when programming trading strategies. The good news is that the developers probably will implement the possibility to start several Expert Advisors on one chart. So traders will be able to create EA-indicators with objects and without trading. Such EA's will operate like standard indicators.

So what can we do now about this limitation? Well, the task is now solved by starting a trading EA in one chart and the EA-indicator that is using objects in the second one, and then implement the exchange between them. But i really hope that the developers of MQL5 will remove this limitation in the near future.

Update: MetaQuotes added the possibility to use graphical objects in indicators with new builds of Metatrader 5 beta. See details here.

Analytics is one of the most important components of MetaTrader 5. Based on analytical data, a trader can decide what operation to execute, when to do it and what profit could be gained. The MetaTrader 5 offers you wide analytical possibilities!

Charts
Charts constitute a work field for technical analysis. This is where dynamics of security quotes are featured, technical indicators and graphical objects are applied. The number of charts that can be used in a terminal is unlimited, and they can be positioned in any way. This enables traders to adjust their workplaces to their own needs.

Every chart can be individually set up. Traders can use the detailed setup of color schemes, displaying of additional data objects and scaling, which allows the configuration of every chart according to the needs of a certain analytical tool. For example, you can setup the displaying of separators for larger periods, the OHLS line, and the chart scaling for the adequate featuring of Gann tools.

MetaTrader 5

Chart Properties Window

All the chart settings can be saved in Templates and Profiles. Templates store almost all the parameters of a chart: its type, color scheme, scale, applied technical indicators, graphical objects and others. In Profiles you can save charts with their templates, as well as their location. All these tools enable you to quickly set up your workplace.

MetaTrader 5

Charts Profiles and Templates

In the client terminal, the history of quotes for each security is used for building charts. In MetaTrader 5, the history is stored as M1 (one minute) only, and all the charts are built based on these data. The terminal supports 21 timeframe for each security, starting from a minute to a month one.

The main limitation of timeframes is their multiplicity: one hour must contain an integer number of minute periods, and a day must consist of an integer number of hour periods. According to this rule, the following timeframes are available in the terminal: M1, M2, M3, M4, M5, M6, M10, M12, M15, M20 and M30.The available hour periods are: H1, H2, H3, H4, H6, H8 and H12. Three more timeframes are D1, W1 and MN1. So many available timeframes allow using any analytical tools, detecting long and short-term trends, and precisely defining entry and exit points.

MetaTrader 5

Timeframe Toolbar

The terminal is installed with an empty history. In order to upload data, open the corresponding chart, and minute quotes for the previous 30 days will be uploaded. If you need more data (for example, if your indicator uses large periods for calculation), simply move your chart to the beginning, and additional history will be uploaded.

A space-efficient format of data storing is implemented in MetaTrader 5. Thus, the ten years' 1-minute history of quotes for GBPUSD takes as little as 10 megabytes. Having uploaded this history once, you can build all the charts for this symbol, from M1 to MN1.

The terminal offers three chart types to display data: linear chart, candlesticks and bars. So, you can choose the most convenient one for analyzing prices. To help you analyze, the terminal contains 38 built-in technical indicators and 39 analytical objects.

Indicators
Technical indicators are automatic tools generating signals based on various calculations. The built-in indicators of the MetaTrader 5 terminal cover almost all needs for analytical tools. The terminal offers you the most popular trend indicators, oscillators, Bill Williams' tools and many other instruments. Should you need any specialized tool, you can write it in the MQL5 language or download/purchase a ready-made program.

MetaTrader 5

Technical Indicators in MetaTrader 5

In MetaTrader 5, indicators can be located over a price chart or they can be displayed in a separate window. In calculations, indicators use securities' price quotes, as well as values of other indicators. So, you can create tools for complex trading systems and combine different indicators. For example, you can apply Moving Average to Awesome Oscillator and obtain its signal line.

MetaTrader 5

Indicators Applied to Other Indicators in MetaTrader 5

For every parameter, not only indicator featuring parameters (line color and width, window scale and others) can be chosen, but also calculation parameters can be set. For example, instead of the default period of 10 bars, 50 or 150 bars can be set for the Moving Average. Besides, different levels can be applied to indicators to make analysis easier (constructing channels, support/resistance lines, etc.).

Objects
Unlike indicators, analytical objects aren't automatic, and should be applied to a chart or indicator manually. Custom objects can't be developed in MQL5, that's why we tried to include as many analytical objects as possible, to help traders analyze prices.

MetaTrader 5

'Simple' Analytical Tools in MetaTrader 5

MetaTrader 5 contains 39 analytical objects. You can use simple tools to mark different points, levels, limits and areas: arrows, labels, shapes, lines and pictures. Terminal also offers more complex Gann tools, Fibonacci and Elliott tools, and channels to help you detect regularities in price dynamics.

MetaTrader 5

Interactive analytical Tools in MetaTrader 5

Another important group contains interactive objects. They are buttons, entry fields and charts. Buttons and entry fields are used in MQL5 programs. For example, some actions of an expert Advisor can be assigned to a button, and parameters can be transmitted to an EA through an entry field. The Charts object is a picture-in-picture function allowing to impose an additional chart of any security to the current price chart. This enables you to follow the dynamics of several symbols and analyze them.

Article Source

metatrader 5 beta
At last some good news from MetaQuotes about the Metatrader 5 public beta:
About a month ago, we started a closed beta testing of the MetaTrader 5 client terminal. Totally, we've received about 300 bug reports and suggestions from our testers. The most of bugs have been fixed, while suggestions have been considered, and we're planning to implement them. Since the testing started, we've released about 20 builds of the client terminal. We'd like to thank 30 members of the MQL4.community, who tested the terminal and helped to make it better. Your help is very important to us.

As we've promised, the closed beta testing would be followed by the public one. During this stage any person can download the terminal and try it. The start of the public testing is planned for 12 October, 2009. Follow the news.

Hopefully, the sites metatrader5.com and mql5.com will be up too. Anyway, when the beta is available, i will post a link here.


Update: Metatrader 5 Public Beta is released

metatrader 5

About 2 weeks ago, the beta version of Metatrader 5 was sent to a selected group of developers from the MQL4 community. One of them has posted a small review of the upcoming trading platform Below are some of his findings.



We have now the long-awaited MetaTrader 5 and MQL5

metatrader 5
This is not Photoshop - it's MQL5.

Practically, everything what many developers wanted from MQL 5 and Metatrader 5 was implemented and realized at the highest level. The major change in MQL5 is the introduction of OOP (Object-oriented programming). Professional programmers have now more opportunities, but those who learned to write in MQL4, can use the MQL4 programming in MQL5 without the benefit of OOP. The only difference is functionality, the only thing that must be learned. For example, "Bid" and "Ask" variables no longer exist. To get the "Bid" value, we must use the function:
SymbolInfoDouble(Symbol(),SYMBOL_BID);
The frequently used functions Low [0] or iLow (Symbol (), PERIOD_D1, 0) are also gone, but you can easily recreate them. Historical data functions have now the opportunity to take the historical data from point to point, from one particular bar to another specific bar or on a specified time prior to this. So now you dont have to take the entire visible range of historical data:
MqlRates rates_arrayG[];
Int Bar=30; // read only 30 bars, beginning from 0;
iCopBar=CopyRates(Symbol(),PERIOD_M1,0,Bar,rates_arrayG);
This innovation greatly save memory and time simultaneously.

Some functional improvements that I expected from MQL5:

- Function OnTimer () for processing timer events ( EA can now be dependent of the tick arrival);
- OnTrade () - function for processing trade events - opening and closing of the trading position or volume change;
- OnChartEvent () - event handling of the mouse and keyboard on the chart.

Function OnTimer () is called, if we pre-trigger the timer in a predefined function OnInit (event handler initialization expert). Example:

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
EventSetTimer(1); //every second, we will turn to OnTimer ()
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit()
{
EventKillTimer(); // required to cancel the requetst to the timer
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTimer()
{
MqlDateTime str1;
TimeGMT(str1); // new function to get GMT time
Comment(str1.hour
,str1.min
,str1.sec
,str1.day
,str1.mon
,str1.year
,str1.day_of_year
,OrdersTotal()
,PositionsTotal()
);
}
So now we can get control not only on the arrival of tick, as before, but also on a timer, that allows you to write full-fledged program operated in real time. This feature allows us to create more featured systems.

The function OnTrade () is called when any of the trade events is happening: placing orders, StopLoss or TakeProfit, changing levels of stoploss or takeprofit, editing or deleting a pending order.

So the monitoring of trading operations events is now much easier than before. There is no need for the checking of the orders on ticks or bars, what previously had to be done in MQL4. So the speed is now much better, particularly in optimization.

The function OnChartEvent () is called at multiple events. I did not test each, but the list of events is impressive:

- CHARTEVENT_KEYDOWN - keyboard is pressed;
- CHARTEVENT_OBJECT_CLICK - mouse click on the graphical object on chart;
- CHARTEVENT_OBJECT_DRAG - move of the graphical object using the mouse;
- CHARTEVENT_OBJECT_ENDEDIT - finishing editing the text CHARTEVENT_CUSTOM + n - ID of the user events;
- CHARTEVENT_CUSTOM_LAST - latest.

With MQL5 we can control the trading and graphics on a new functional level, as was promised by the developers
metatrader 5
Graphic objects allow you to create information panels.

New graphics, buttons, input fields. The control of graphics is now on a fantastic level, you can even insert pictures from files - custom designs for lovers of non-standard design. This is not Photoshop, it is possible with MQL5 and MetaTrader 5. There are new opportunities, you can create your own buttons and their input fields, such as adding an interface button that will close all open orders. Or quick buy or Sell in a single click, with pre-fielded parameters of stop loss and take profit.

If we talk about the terminal itself, the first you will notice is the big number of timeframes. But the abundance of minute timeframe, probably will please those who have so long dreamed about it. Dreamers of non-standard timeframes are one step away from a custom timeframe, which, however, can be considered as unnecessary. Method of data storage is now 1 minute, so there are no more problems with the synchronization of different timeframes - this is a very important technological solution.

metatrader 5
The history folder: no more files with different timeframes:


metatrader 5
Another improvement: Logs can now be cleared.

metatrader 5 statement
Metatrader 5 statement.


About 2 weeks until public beta. ;)

The trading system in MetaTrader 5 differs from that of MetaTrader 4 in its basics. First of all, four types of trade operation execution are supported in MetaTrader 5: Market, Instant, Request and Exchange. Secondly, the new terminal accepts the strict delimitation between the notions of Order, Trade and Position.

  • Order. This is the direction to a brokerage company to buy or sell a financial security. There are two major types of orders: market and pending. Two more special orders are available in the new terminal - Take Profit and Stop Loss.
  • Trade. It`s the fact of security buying or selling. A Buy is performed at the Ask price, while Sell is done at the Bid price. A trade can be opened as the result of market order execution or pending order activation.
  • Position. It`s a market obligation, number of bought or sold security contracts. A long position is a symbol bought expecting the security price raise. A short position is the obligation to supply it expecting the further price fall. Only one position for a certain security can exist on a trade account.
Differences between trade positions in MetaTrader 4 and MetaTrader 5:

metatrader 5

Besides the Buy and Sell market orders, 6 types of pending orders are supported:

  • Buy Limit is a trade Buy order at the Ask price equal to or better than that indicated in the order. Usually orders of this type are placed expecting that the symbol price falls till a certain level and starts raising then.
  • Buy Stop is a trade Buy order at the Ask price equal to or better than that indicated in the orders are placed when a security price us expected to get over a certain level and continue growing.
  • Sell Limit is a trade order to sell at the Bid price that is equal to or better than that indicated in the order. In this case a security price is expected to raise till a certain level and go downwards after that.
  • Sell Stop is a trade order to sell at the Bid price that is equal to or better than that indicated in the order. The current price level is above the value indicated in the order. Usually such orders are placed when a security is expected to fall down to a certain level and continue the downward moving.
  • Buy Stop Limit - this type of orders is the combination of the first two types being a stop order for placing a Buy Limit order. As soon as the Ask price reaches the specified value, a Buy Limit order will be placed at the level indicated in the order. The current price level is lower than that, reaching which a pending order will be set.
  • Sell Stop Limit - this type is the stop order to place a Sell Limit order. As soon as the future Bid price reaches the value specified in the order, a Sell Limit will be placed for the level indicated in the order. Here the current price level is above the value, reaching which a pending order will be placed. The price of the pending order is above the level of its placing.
Pending Orders in MetaTrader 5 Client Terminal:

metatrader 5

All these possibilities enable you to flexibly control all trading activities and implement almost any trading strategy.

How Does It Work?

An order to execute a trade with indicated parameters is sent to a broker from the client terminal. The order correctness is checked on the server. Are all the parameters (balance, lot, price, etc.) indicated correctly? If any of parameters does not meet the requirements, the order is rejected. If everything is correct, a trade order is placed to the Order Queue, after which it is sent to a dealer or to the market. An order can be also rejected in the market (stock exchange) or by the dealer.

Trading operations Execution in MetaTrader 5:

metatrader 5

An order turns into a trade if all its parameters are correct and it has been executed in the market. Depending on the current position for the security, the trade can result in the position increase, decrease or closing.

Example: we've got one position for EURUSD 1 Lot. If another lot is bought, the position will be increased to 2 lots. If 1 lot is sold, the position will be closed. If 0.7 lots are sold, the position will diminish to 0.3 lots.

Fill Policy

Besides common order execution rules set by a broker, trade operation execution policies can be set in MetaTrader 5. These policies allow making trading activities more flexible and setting strict parameters to manage the execution of trade operations.

metatrader 5

  • All or None
    With this condition, a trade can be executed only for the indicated volume and at the price equal to or better than that indicated in the order. If the enough security volume is currently unavailable in the market, the order won't be executed.
  • Cancel Remains
    In this case a trader agrees to have a trade executed for the volume maximally available in the market within the volume specified in the order and at the price equal to or better than that indicated in the order. No additional orders are placed for the deficient volume.
  • Return
    In this case a trader agrees to have a trade executed for the volume maximally available in the market within that specified in the order and at the price equal to or better than that indicated in the order. Besides, an additional order is placed for the deficient volume at the price indicated in the order.
Source

A few days ago MetaQuotes published a MQL5 referenced guide in Russian. The English version is not coming out yet. However, if you use a translation service, for example Google Translate, you should understand it without much problems if you are good in MQL4, because the terminology is basically the same. Anyway, if you have problems with the translation, you can always ask for help on the MQL4 forums or here in the comments, i will help you.

Regarding MetaTrader 5, the wait continues:

metatrader 5

Lets hope MetaQuotes will publish the MetaTrader 5 public beta in September when people get back from their holidays. Traders should have time to prepare for the Automated Trading Championship in 2010 (Expert Advisors written in MQL5). Maybe they have problems with the new NFA rules* and are reworking the implementation of them?

*NFA ruling compliance: Recently the NFA issued new regulations prohibiting traders from hedging (having long and short positions open on the same currency pair at the same time).

MT5 has a new integrated development environment called MQL5 which includes MetaEditor 5, MetaTrader 5 Strategy Tester and MetaQuotes Language 5 (MQL5). Unfortunately the MQL4 and MQL5 languages are not compatible. This means that every custom indicator and EA must be rewritten to work with Metatrader 5. It is not clear yet if there will be a tool which converts the MQL4 source code to MQL5 or allows MQL4 executables to run in MT5. The official statement of MetaQuotes about this:

You should also understand that we doing it not to make you redo the EA developments every time when we launching a new platform. From the beginning of Metatrader 5 development we thought that we will be able to save the compatibility. And we said about it many times. But the numerous traders/developers requests made us change our mind. We`ve understood that just cant make a new language compatible. At the same time we have made MQL5 more powerful and in this way we gave you, traders and developers, more abilities - that was our main goal in developing of MQL5 IDE. From one side new language with the new abilities and from the other side - MQL4 and MQL5 compatibility. Unfortunately, these two aims cant be reached at the same time.

According to MetaQuotes, the MQL5 language is distinct for high speed of execution and approaches C++ in terms of this parameter. As compared to MQL4, the new language boasts up to 20 times faster execution speed. We know that execution speed is everything when developing ea's and scripts that sometimes need to crunch huge amounts of data in conjunction with real-time price movements. MQL5 is now more object oriented, what makes the development of EAs quicker, easier and more flexible, especially for autotrader developers. This also allows using more complex EA's able to process large amounts of data per time unit and therefore obtain more precise forecasts of price dynamics. The MQL5 programming environment incorporates intellisense system which, as most developers would agree, speeds up the development process. It also has a built-in debugger for testing and quickly find errors and fix them. The MetaTrader 5 Strategy Tester will not be much different from the tester in MT4 besides more advanced report system.

metatrader 5

Here i will post all information about the MQL5 documentation and tutorials. This post will be regularly updated with links to new content.



- Moving from MQL4 to MQL5t
- Rewrite MQL 4 to MQL 5 Script
- MQL4 to MQL5 Porting Table
- MT5, Metaeditor 5 and MQL5 User guides
- Learning programming for the Metatrader 5 platform
- MQL5: No graphical objects in indicators
- Review of the Metatrader 5 Beta
- MetaTrader 5 Trading System
- Metatrader 5 development environment: MQL4 vs MQL5
- MetaTrader 5 Client Terminal - first screenshots and information
- Interview with Stanislav Starikov, leading programmer of MQL5 about the development of MQL5
- Suggestions for Metatrader 5 and MQL5
- Metatrader 5 and MQL 5 Development - questions and answers

Metatrader 5 and MQL 5 Development - questions and answers:

Q: Can you make available BNF description of MQL5? If not BNF, do you have formal syntax descriptive document? If no formal syntax description, why not?
A: You can use C++ BNF description (we cannot publish it because this form is hardcoded in our project)

The differences as compared to C++ are:

* No class inheritance
* No address arithmetic
* No operators overload (it will probably be included later)
* No 'goto' operator
* No ternary operation expr ? op1 : op2; (it will probably be included later)

The syntax description will be embedded in MetaEditor help files.

Q: Can you make available Client Terminal Functionality Documentation? Eg, callable functions, global variable functionality, error code handling embeded within Terminal instead of current random hit and miss programmer attempts at error handling?
A: No, we cannot as yet. You should consider the functionality described in MQL4. However, the functionality will be expanded considerably.

Q: What do you see as cut off date when MQL4 will no longer be accepted as platform? Will all MQL4 S/W become redundant unless migrate to MQL5 syntax...?
A: You should not worry about "cut-off" date for MQL4. The upward compatibility of the languages will be kept, with some rare exceptions.

Q: What is the syntax's difference between MQL4 and MQL5?
A: It may be difference between OrderSend (MQL4) and OrderSend (MQL5) function calls. But this is no matter of MQL5 syntax - it is just feature of Metatrader 5 trading platform.

Q: Will MQL5 be multithread to take all quad-core processors capacity on Tester?
A: Tester is planned to be multithread. But this is client terminal feature not MQL5.

Q: Is it planned that MQL5 will come out for MT4, not with a new Metatrader 5?
A: No, it is not. MQL5 will come out for Metatrader 5. As was said in the interview, "the development of Metatrader 5 is in full swing, and the development of MQL5 is at its closing stage".

Q: Will this new MQL5 support event-driven programming? In event-driven environment, we can just define what kind events we want to handle and write a routine (function) to process that event.

Automatic trading basically processes events that occur: event when an indicator hits certain value, event when price triggers an order, event when an open order is being closed, event when an open order causing margin call/stop out, etc. But in MQL4 we are lacking such a feature, so the solution is quite unnatural because we have to check every condition we need to know inside the start() function on every tick of the applied chart. Consider an example that an account is nearing a stop-out because of an open position. However the EA is applied only to (unfortunately slower) one chart, different from the pair currently traded. It misses a call to start() and stop-out happens. This wouldn't happen if there is an event-driven function to handle the event.

A: Events are planned. multitimeframes and multicurrencies testing planned too. multithreaded tester optimization... But these all things are Metatrader 5 features not MQL5. Debugger is planned. What is event processing in the MQL5? Just appropriate functions like OnNewTick, OnNewBar, OnOrderClosed, OnPendingTriggered, OnAlert and so on placed in the events handling queue. That's all. Events handling (first part of event processing) is matter of Metatrader 5 not MQL5.

Q: Does language design contain a more flexible (read usable) #define syntax; eg, parameters. Basically, minimal implementation as per C. Preprocessing of source code is old and known task with many code bases to choose from. Preprocessing does not impact compiler and added benefits of macro/define functionality are enormous.
A: Preprocessing was introduced in the pure C for portability purposes between different platforms and compilers. Preprocessing causes some hardly detectable errors. The answer is "No". Simplest #define only.

Source

The MetaQuotes workshop entitled "MetaTrader 5 - Next Generation Trading Platform" took place on 1-3 April in Kazan, Russia during which the developers have given a in-depth look at the next gen trading platform. The participants from all around the world have met the developer team of MetaTrader 5 and discussed functionalities and ideas about the next generation of the popular trading platform.

The participants have learned about the latest new features added to MetaTrader 5 like trading stocks, options, futures in addition to Forex using one single platform and how it can be utilized for their businesses.

Quoting from another trader/programmer who said: "MetaTrader has gained a huge following in the past five to six years, particularly with the release of MT4. MetaTrader 5 will likely prove to be a true next generation platform, with structural changes that will make it an altogether different and more powerful animal. I look forward to its release."

Here are some of the futures of the upcoming Metatrader 5 platform:

* Working with MQL5 will be easier than MQL4 (for a number of reasons, including reading/writing programs);
* There will be more data types, structures, classes;
* Faster execution speed;
* Like MT4, the development environment will be released before the trading terminal;
* Easier to transfer C++ source codes into MQL5.

Read more about the new features here: Development of MetaTrader 5 and MQL5.

MetaQuotes will probably release MetaTrader 5 by Fall 2009.