Order Book, also known as Market Book, market depth, price glass, Level 2 , is a dynamically updated table provided by the broker with data on the current volumes of trading orders for buying and selling for various price levels near the Bid and Ask of a particular financial instrument.
MetaTrader 5 provides the ability to broadcast a glass of prices, but only in real time. This OrderBook History Library allows you to read the states of the glass in the past from the archives created by the OrderBook Recorder expert. The library can be used in indicators and experts, including in the tester.
This library, in particular, is used for reading the glass by the OrderBook Cumulative Indicator and the OrderBook History Playback demo expert.
Below is an example of a header file for connecting the library:
The input parameters are defined for convenience – so that their values can be passed to the OrderBook_Init function.
- OrderBook_FileFolder – the name of the root folder where the subfolders with the cup files are located; by default, “Books” is used in OrderBook Recorder; each subfolder is named by the symbol name; for example, for the GAZP ticker, we get the MQL5 files/Files/Books/GAZP/*. hob;
- OrderBook_UseCommonFiles-option to read files from the folder of the current terminal (false, by default) or from the shared folder of all terminals (true);
- OrderBook_TimeZoneCorrection-correction of the date and time for cases when the archives of the glass are read in the terminal, where the server time zone is different from the one used when recording archives; set in seconds; for example, if the glass was saved with the server time GMT 3 and then reproduced on the server quotes with GMT 2, the correction should be equal to 1 hour (-3600 seconds), since at GMT 2 the times are 1 hour behind (i.e. less) from GMT 3;
[spoiler title=”Read More…”]
Functions
- OrderBook_Init-library initialization function, should be called from OnInit; as the first parameter, a pointer to the OnBookEvent event handler should be passed;
- OrderBook_MarketBookAdd, OrderBook_MarketBookRelease, OrderBook_MarketBookGet-functions that are completely similar to the corresponding MQL functions; when working online, standard functions are directly called – this allows you to embed the library, practically without changing the code; when working in the tester, the library accesses the archive; subscription is allowed only for the current graph symbol;
- OrderBook_MarketBookPeek is an analog of OrderBook_MarketBookGet, which always accesses the archive-both in the tester and online; there is no call to MarketBookGet;
- OrderBook_OnTick – an optional option to run the library in the tester from onTick;
- OrderBook_OnTimer – an optional option to run the library in the tester from OnTimer;
- OrderBook_CheckForEvents – an optional option to run the library in the tester and online on demand, for a given date and time;
The #define ORDERBOOK_SUBSTITUTE declaration implicitly replaces all calls to standard functions in your code with library calls before including the header file.
[/spoiler]