Before sending a request for a trading operation to the trade server, it is recommended to check that it is completed without formal errors. The check is carried out by the OrderCheck function, to which we pass the request in the MqlTradeRequest structure and the receiving variable of the MqlTradeCheckResult structure type.
In addition to the correctness of the request, the structure enables the evaluation of the account state after the execution of a trading operation, in particular, the balance, funds, and margin.
struct MqlTradeCheckResult
|
The following table describes the fields.
Field |
Description |
|---|---|
retcode |
Assumed return code |
balance |
The value of the balance, which will be observed after the execution of the trade operation |
equity |
The value of own funds, which will be observed after the execution of the trade operation |
profit |
The value of the floating profit, which will be observed after the execution of the trade operation |
margin |
Total locked margin after a trade |
margin_free |
The volume of free own funds that will remain after the execution of the trade operation |
margin_level |
The margin level that will be set after the execution of a trade operation |
comment |
Comment on the response code, description of the error |
In the structure which is filled by calling OrderCheck, the retcode field will contain a result code from among those that the platform supports for processing real trade requests and puts in a similar retcode field of the MqlTradeResult structure after calling trading functions OrderSend and OrderSendAsync.
Return code constants are presented in MQL5 documentation. For their more visual output to the log when debugging Expert Advisors, the applied enumeration TRADE_RETCODE was defined in the file TradeRetcode.mqh. All elements in it have identifiers that match the built-in constants but without the common "TRADE_RETCODE_" prefix. For example,
enum TRADE_RETCODE
|
So, the use of TRCSTR(r.retcode), where r is a structure, will provide a minimal description of the numeric code.
We will consider an example of applying a macro and analyzing a structure in the next section about the OrderCheck function.