- Expert Advisors main event: OnTick
- Basic principles and concepts: order, deal, and position
- Types of trading operations
- Order types
- Order execution modes by price and volume
- Pending order expiration dates
- Margin calculation for a future order: OrderCalcMargin
- Estimating the profit of a trading operation: OrderCalcProfit
- MqlTradeRequest structure
- MqlTradeCheckResult structure
- Request validation: OrderCheck
- Request sending result: MqlTradeResult structure
- Sending a trade request: OrderSend and OrderSendAsync
- Buying and selling operations
- Modying Stop Loss and/or Take Profit levels of a position
- Trailing stop
- Closing a position: full and partial
- Closing opposite positions: fill and partial
- Placing a pending order
- Modifying a pending order
- Deleting a pending order
- Getting a list of active orders
- Order properties (active and historical)
- Functions for reading properties of active orders
- Selecting orders by properties
- Getting the list of positions
- Position properties
- Functions for reading position properties
- Deal properties
- Selecting orders and deals from history
- Functions for reading order properties from history
- Functions for reading deal properties from history
- Types of trading transactions
- OnTradeTransaction event
- Synchronous and asynchronous requests
- OnTrade event
- Monitoring trading environment changes
- Creating multi-symbol Expert Advisors
- Limitations and benefits of Expert Advisors
- Creating Expert Advisors in the MQL Wizard
MqlTradeCheckResul structure
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.