Discussion of article "MQL5 Cookbook: Implementing Your Own Depth of Market"

 

New article MQL5 Cookbook: Implementing Your Own Depth of Market has been published:

This article demonstrates how to utilize Depth of Market (DOM) programmatically and describes the operation principle of CMarketBook class, that can expand the Standard Library of MQL5 classes and offer convenient methods of using DOM.

MQL5 language is constantly evolving and offering more opportunities for operation with exchange information every year. One of such exchange data types is information about Depth of Market. It is a special table showing price levels and volumes of limit orders. MetaTrader 5 has a built-in Depth of Market for displaying limit orders, but it is not always sufficient. First of all, your Expert Advisor has to be given a simple and convenient access to Depth of Market. Certainly, MQL5 language has few special features for working with such information, but they are low-level features that require additional mathematical calculations.

However, all intermediate calculations can be avoided. All you have to do is to write a special class for working with Depth of Market. All complex calculations will be carried out within Depth of Market, and the class itself will provide convenient ways for operation with DOM prices and levels. This class will enable an easy creation of the efficient panel in a form of an indicator, which will be promptly reflecting the current state of prices in Depth of Market:


Fig. 1. Depth of Market displayed as a panel

After reading the first chapter of this article, it will become clear that the regular Depth of Market offered by MetaTrader 5 has impressive capabilities. We will not try to duplicate all these multiple opportunities in our indicator, as our task will be completely different. With a practical example of creating user-friendly Depth of Market trading panel we will show that the principles of object-oriented programming allow relatively easy handling of complex data structures. We will ensure that it won't be difficult to gain access to Depth of Market directly from your Expert Advisor with MQL5 and, consequently, to visualize its representation as it is convenient for us.

Author: Vasiliy Sokolov

 

Hello,

Thanks so much for the contribution.

It is exactly what I was searching for.

Depth of Market can be a great indication for scalpers.

But the problem is I never really see depth of market volume information in my terminals.

How to get access to the volume information provided by the broker? 

 
Hi! Market Book is usually only available on the exchange markets. Connect to any exchange and use it!
 

hi there, thanks for the article, very straightforward.

Im trying to call some "N" dephts of market on the EA and im trying to modify the MarketBoook.mqh code in order create new doubles and integers that could "invoke" those 2nd, 3rd, "N" dephts directly , without looping and wasting time.


edit:i managed to do it, coding some new integers and doubles inside the MarketBoook file, and now im calling then from other mq5's.

the question that remains is: is there some other way that would be more efficient, or is that, as you show in the article, the most optimized way of doing so?


thanks a lot

 
Pedro Miranda:

Hello,

Thanks so much for the contribution.

It is exactly what I was searching for.

Depth of Market can be a great indication for scalpers.

But the problem is I never really see depth of market volume information in my terminals.

How to get access to the volume information provided by the broker? 

Yep, what said Pedro is obvious.

No broker using metaQuotes platforms send volumes data.

So, I dunno why you are saying the opposite regarding the values provided by MqlBookInfo

 

Hi!

I was wondering how can I accomplish the following, looking at the following DOM:


Let's say I want to market buy 21 volume. I will pay the average price of 56842. But if I buy 22 volume, the average price will be (21 * 56842 + 1* 56843) / (21 + 1) = 56842.05. If I buy 30 volume, the average price will be (21 * 56842 + 1 * 56843 + 8 * 56844) / (21 + 1 + 8) = 56842.57. If I want to buy market buy 100 volume, average price will be 56845.56.

I was trying to figure out an algorithm for it, but I am completely clueless. I thought about about doing two recursive loops to fill an array and then calculating it's average, as also trying to calculate and weighted average.

Anyone?

 

How can I use the volume of the best selling price for the code

WHAT IS THE CODE??

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
To obtain the current market information there are several functions: SymbolInfoInteger(), SymbolInfoDouble() and SymbolInfoString(). The first parameter is the symbol name, the values of the second function parameter can be one of the identifiers of ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE and ENUM_SYMBOL_INFO_STRING. Some symbols...
 
i copied everything in the folders but its not working. Too bad. :-(