OrderBook History Library
- ライブラリ
- Stanislav Korotky
- バージョン: 1.6
- アップデート済み: 27 9月 2024
- アクティベーション: 5
Order Book, known also as Market Book, market depth, Level 2, - is a dynamically updated table with current volumes of orders to buy and to sell specific financial instument at price levels near Bid and Ask.
MetaTrader 5 provides the means for receiving market book from your broker, but in real time only, without access to its history. The library OrderBook History Library reads market book state in the past from archive files, created by OrderBook Recorder. The library can be embedded into your indicators and expert advisers (source codes are required), and then they can be tested with the market book data in the tester.
In particular, the library is used in the indicator OrderBook Cumulative Indicator and demo expert adviser OrderBook History Playback.
Here is an example of the header file for including the library into your MQL program:
input string OrderBook_FileFolder = "Books"; input bool OrderBook_UseCommonFiles = false; input int OrderBook_TimeZoneCorrection = 0; typedef void (*pOnBookEvent)(const string &symbol); #import "OrderBook.ex5" void OrderBook_Init(pOnBookEvent ptr, const string folder, const bool common, const int offset); bool OrderBook_MarketBookAdd(string symbol); bool OrderBook_MarketBookRelease(string symbol); bool OrderBook_MarketBookGet(string symbol, MqlBookInfo &bookArray[]); long OrderBook_MarketBookPeek(string symbol, MqlBookInfo &bookArray[]); void OrderBook_OnTick(); void OrderBook_OnTimer(); bool OrderBook_CheckForEvents(datetime current); #import #ifdef ORDERBOOK_SUBSTITUTE #define MarketBookAdd OrderBook_MarketBookAdd #define MarketBookRelease OrderBook_MarketBookRelease #define MarketBookGet OrderBook_MarketBookGet #endif
The input parameters are defined for convenience - they should be passed into the function OrderBook_Init.
- OrderBook_FileFolder - a name of the root folder, where subfolders and files of the market books are stored; by default - "Books"; every subfolder is named according to specific work symbol; for example, the ticker GAZP will form the files MQL5/Files/Books/GAZP/*.hob;
- OrderBook_UseCommonFiles - an option for reading files from the data folder of the current terminal (false, by default) or from the common data folder for all terminals (true);
- OrderBook_TimeZoneCorrection - a correction of date and time, which is required in case, that archives are read in a terminal with a timezone, which differs from a timezone of the terminal where the archives were created; specified in seconds; for example, if the market book was saved with the server time in GMT+3, and then it's applied on quotes from a server, where time is in GMT+2, the correction should be 1 hour (-3600 seconds), because times in GMT+2 go 1 hour late in comparison to (i.e. they are 1 hour smaller than) GMT+3; 15:00 in GMT+3 is 14:00 in GMT+2;
Functions
- OrderBook_Init - initialization of the library, should be called from OnInit; the first parameter should be the event handler OnBookEvent;
- OrderBook_MarketBookAdd, OrderBook_MarketBookRelease, OrderBook_MarketBookGet - analogous functions to corresponding standard MQL functions; while working online, the standard functions are called internally - this way, emdedding the library will not alter the source code logic; while working in the tester, the library retrieves data from the files; the subscription for market book for current chart's symbol only is allowed;
- OrderBook_MarketBookPeek - similar to OrderBook_MarketBookGet, but always reading data from files - both in the tester and online; MarketBookGet is never called;
- OrderBook_OnTick - optional execution of the library for latest tick from OnTick; only for the tester, online does nothing;
- OrderBook_OnTimer - optional execution of the library for latest known time from OnTimer; only for the tester, online does nothing;
- OrderBook_CheckForEvents - optional execution of the library from the tester and online, ad hoc - for specified date and time;
Adding the line #define ORDERBOOK_SUBSTITUTE into the source code before including the header file will implicitly replace all calls of the standard market book function with corresponding library's functions.
Я уже было хотел делать что-то подобное сам, но подсказали что есть библиотека в магазине для тестирования/отладки стаканных экспертов. Все установил, все работает. Спасибо, разработчику, ты сэкономил мне, возможно, месяцы работы.