Discussion of article "Library for easy and quick development of MetaTrader programs (part XXVI): Working with pending trading requests - first implementation (opening positions)"
//--- Data location in the magic numberber int value //----------------------------------------------------------- // bit 32|31 24|23 16|15 8|7 0| //----------------------------------------------------------- // byte | 3 | 2 | 1 | 0 | //----------------------------------------------------------- // data | uchar | uchar | ushort | //----------------------------------------------------------- // descr |pend req id| id2 | id1 | magic | //----------------------------------------------------------- //--- Return (1) the specified magic numberber, the ID of (2) the first group, (3) second group, (4) pending request from the magic numberber value ushort GetMagicID(void) const { return ushort(this.Magic() & 0xFFFF); } uchar GetGroupID1(void) const { return uchar(this.Magic()>>16) & 0x0F; } uchar GetGroupID2(void) const { return uchar((this.Magic()>>16) & 0xF0)>>4; } uchar GetPendReqID(void) const { return uchar(this.Magic()>>24) & 0xFF; }
There exists a convenient function for extracting bits from a number.
//--- extract cnt bits at the kth bit position uint _getBits(const uint number,uint pos,uint cnt=1) const { return (number >> pos) & ((1 << cnt) - 1); } ushort GetMagicID(void) const { return ushort(_getBits(this.Magic(),0,16)); } uchar GetGroupID1(void) const { return uchar(_getBits(this.Magic(),16,4)); } uchar GetGroupID2(void) const { return uchar(_getBits(this.Magic(),20,4)); } uchar GetPendReqID(void) const { return uchar(_getBits(this.Magic(),24,8)); }
Is there an implementation in the library to open an immediate market execution?
Yes

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
New article Library for easy and quick development of MetaTrader programs (part XXVI): Working with pending trading requests - first implementation (opening positions) has been published:
In this article, we are going to store some data in the value of the orders and positions magic number and start the implementation of pending requests. To check the concept, let's create the first test pending request for opening market positions when receiving a server error requiring waiting and sending a repeated request.
Compile and launch the EA. Turn off the Internet and wait till the following image appears in the lower right corner of the terminal:
After disabling the Internet and clicking Sell, the trade server returns the error and the following entries are displayed in the journal:
After receiving the error, the library creates a pending request with the parameters set during the unsuccessful attempt to open a short position.
The pending request also features the number of attempts and the waiting time of 20 seconds.
Then enable the Internet to restore the connection to the trade server:
As soon as the connection is restored, the library starts handling a pending request sending it to the server. As a result, we have an open position with journal entries:
As we can see, after restoring the connection to the trade server, trading for the current account was enabled with a delay.
But the pending request did the trick anyway...
Also, we can see the real magic number 17629307 in the journal followed by the magic number defined in the EA settings in brackets (123) plus another entry G1: 13 informing that the first group ID is equal to 13, while the second group ID is absent — its value turned out to be equal to zero, therefore there was no second entry with the G2: XX second group ID.
Author: Artyom Trishkin