Discussing the article: "Trade transactions. Request and response structures, description and logging"

 

Check out the new article: Trade transactions. Request and response structures, description and logging.

The article considers handling trade request structures, namely creating a request, its preliminary verification before sending it to the server, the server's response to a trade request and the structure of trade transactions. We will create simple and convenient functions for sending trading orders to the server and, based on everything discussed, create an EA informing of trade transactions.

MQL5 features the OrderSend() function for placing pending orders, opening positions, as well as for changing orders and positions. The first input of the function is the structure of the MqlTradeRequest trade request. The 'action' field of the structure indicates the type of action to be performed, and the remaining fields are filled in depending on the selected action in the 'action' field. Thus, we send various requests to the server by passing the parameters necessary for a trade request to the function.

Author: Artyom Trishkin

 

Thank you, Artyom, for concentrating all the necessary information in one article! I added it to my favourites.

Regards, Vladimir.

 

Thanks for the interesting article. But it is a pity that very little attention is paid to the OrderCheck() function

I hope for a separate article devoted to this useful function...

 
Alexey Viktorov #:

Thanks for the interesting article. But it is a pity that very little attention is paid to the OrderCheck() function

I hope for a separate article devoted to this useful function...

In some old releases of MT5 I came across that OrderCheck() sometimes rejected requests that were actually executed quite successfully. I gave up on it and don't want to test these errors again in combat robots, even though they may have been fixed.

 
Alexey Viktorov #:

Thanks for the interesting article. But it is a pity that very little attention is paid to the OrderCheck() function

I hope for a separate article devoted to this useful function...

I was just writing some "extended help" - a lot of reference information. And everything about OrderCheck is laconic and uncluttered. And there are no excesses in it itself. I have described what, what and how the fields are filled in. They are not filled in all cases. The response of the function with the code is almost always "OK", because I am used to filling out the trade request correctly. If you take the situation about "almost", it is on purpose entered incorrect data to check the work. That is, I have no idea what to describe there, and even for an article.

 
Artyom Trishkin #:

I was just writing some "extended help" - a lot of background information. But everything about OrderCheck seems to be concise and uncluttered. And there are no excesses in it itself. I have described what, what and how the fields are filled in. They are not filled in all cases. The response of the function with the code is almost always "OK", because I am used to filling out the trade request correctly. If you take the situation about "almost", it is on purpose entered incorrect data to check the work. That is, I have no idea what to describe there, and even for an article.

At least few people have carefully read the structure of MqlTradeCheckResult

struct MqlTradeCheckResult
  {
   uint         retcode;             // Response code
   double       balance;             // Balance after the transaction
   double       equity;              // Equity after the transaction
   double       profit;              // Floating Profit
   double       margin;              // Margin requirements
   double       margin_free;         // Free margin
   double       margin_level;        // Margin level
   string       comment;             // Comment to the response code (error description)
  };

And most often they say that this function is intended exclusively, as it is written in the documentation

The OrderCheck() function checks the sufficiency of funds for the required trade operation.

But it is worth paying attention to the fields of the structure "Balance after ..." and "Equity after ...". I am not talking about "Margin requirements" at all. These parameters are very useful. For example, if after making a deal there is "forty kopecks" of equity left on the account... Is it necessary to make such a deal, even if there are enough funds and other parameters of the order are in order? Of course, it is possible to get this value by another method, but in my opinion it is much more favourable to get several useful parameters by one function.

And according to my experience of using it, the response code fixes incorrect SL and/or TP prices in case of a successful check. And not only them. This is what I would like to get an article about. About what other codes work...

Unfortunately OrderCheck() does not report an error.

10018

TRADE_RETCODE_MARKET_CLOSED

The market is closed.


So maybe the developers will finally pay attention to this problem...

 
Alexey Viktorov #:

At least few people carefully read the structure of MqlTradeCheckResult

And most often they say that this function is intended exclusively, as it is written in the documentation

But it is worth paying attention to the fields of the structure "Balance after ..." and "Equity after ...". I am not talking about "Margin requirements" at all. These parameters are very useful. For example, if after making a deal there is "forty kopecks" of equity left on the account... Is it necessary to make such a deal, even if there are enough funds and other parameters of the order are in order? Of course it is possible to get this value by another method, but in my opinion it is much more favourable to get several useful parameters by one function.

And according to my experience of using it, the response code fixes incorrect SL and/or TP prices in case of a successful check. And not only them. This is what I would like to get an article about. About what other codes work...

Unfortunately OrderCheck() does not report an error

10018

TRADE_RETCODE_MARKET_CLOSED

Market closed


So maybe the developers will finally pay attention to this problem....

I don't understand what SL and TP you are talking about? They are not in the fields of the structure...

And about equity, the balance after the transaction ... Well..., you know, I was thinking of saying that it's useful to know that, and that this data should be analysed before sending an order to the server. But didn't I say that? Or should I have made it clear that you shouldn't open a position if you don't have enough for a bun later ) ... . But, you see, I thought, and I think it is clear. That's why I just wrote that you can analyse the filled fields of this structure. And about the fact that "Market closed" is not returned, I did not write (although I wanted to) simply because I forgot ). And I thought that these are return codes of the trade server. They are for all cases of life. Apparently, this code is not for this case. It returns normally in OrderSend. Although yes, to check if the market is closed, you need to send an order - a weak solution. But what is there.

 
Artyom Trishkin #:

I don't understand what SL and TP are you talking about? They are not in the structure fields...

I'm talking about the codes

10014

TRADE_RETCODE_INVALID_VOLUME

Incorrect volume in the query

10015

TRADE_RETCODE_INVALID_PRICE

Incorrect price in the request

10016

TRADE_RETCODE_INVALID_STOPS

Incorrect stops in the request


These codes are returned to the MqlTradeCheckResult structure and are perfectly analysed.

In other words, if you do not want to write, or Rashid does not welcome, I do not insist.

 
Alexey Viktorov #:

I'm talking about the codes

10014

TRADE_RETCODE_INVALID_VOLUME

Incorrect volume in the request

10015

TRADE_RETCODE_INVALID_PRICE

Incorrect price in the request

10016

TRADE_RETCODE_INVALID_STOPS

Incorrect stops in request


These codes are returned to the MqlTradeCheckResult structure and are perfectly analysed.

In other words, if you don't want to write or Rashid doesn't welcome you, I don't insist.

Well, what can you write here except "You can analyse response codes"? Well, a person received such a code - it is clear that the stops are wrong. So it must be processed programmatically so that there are no incorrect stops. Analysing response codes is also analysis. As well as structure fields. That is, everything has been said - analyse and draw conclusions. Or do you think that you need to describe each server response and what actions should be done in this case? Well, this is implemented in the library, which I haven't finished writing yet, but trading has been done there for a long time. With full analysis and making adjustments. Why repeat yourself?

 
Artyom Trishkin #:

Well, what can you write here except "You can analyse the response codes".... Well, a person received such a code - it is clear that the stops are not correct. So it must be processed programmatically so that there are no incorrect stops. Analysis of response codes is also analysis. As well as structure fields. That is, everything has been said - analyse and draw conclusions. Or do you think that you need to describe each server response and what actions should be done in this case? Well, this is implemented in the library, which I haven't finished writing yet, but trading has been done there for a long time. With full analysis and making adjustments. Why repeat yourself?

In order to get and analyse the return code, you should at least understand what this function is and understand its usefulness. This is exactly what I am talking about. The article will give an extended understanding of the function, not just a description from the documentation.

Forum on trading, automated trading systems and testing trading strategies

Discussion of the article "Trading transactions. Structures of requests and responses, description and log output".

Alexey Viktorov, 2023.08.03 13:40

At least few people carefully read the structure of MqlTradeCheckResult

struct MqlTradeCheckResult
  {
   uint         retcode;             // Response code
   double       balance;             // Balance after the transaction
   double       equity;              // Equity after the transaction
   double       profit;              // Floating Profit
   double       margin;              // Margin requirements
   double       margin_free;         // Free margin
   double       margin_level;        // Margin level
   string       comment;             // Comment to the response code (error description)
  };

And most often they say that this function is intended exclusively, as it is written in the documentation

The OrderCheck() function checks the sufficiency of funds for the requiredtrade operation.

That's where I'll leave off.
 
Artyom Trishkin #:
Although yes, to check if the market is closed, you need to send an order - a weak solution. But it is.

Is it still such an impossible task for the creators of the MQL5 programming language - the MarketClosed function without tambourine dancing?

Regards, Vladimir.