Discussion of article "Library for easy and quick development of MetaTrader programs (part XXVII): Working with trading requests - placing pending orders"

 

New article Library for easy and quick development of MetaTrader programs (part XXVII): Working with trading requests - placing pending orders has been published:

In this article, we will continue the development of trading requests, implement placing pending orders and eliminate detected shortcomings of the trading class operation.

In the previous article, we started the implementation of pending trading requests and created the first pending request for opening a position in case an error is received in the trading class after sending a request to the server. In this article, we will resume the development of pending requests and implement creation of a pending request in case of errors occurred when setting pending orders.

While testing the trading class, I have detected some shortcomings. In particular, when initializing symbol's trading objects in the class constructor, hard-set default values were set for them. Not all of those values may have been supported in the symbol specification. This caused server errors when attempting to place pending orders — the server activated the unsupported order expiration type error. This error was not corrected anywhere and eventually led to the inability to place a pending order. When sending a trading request with default values, some unsupported data was also sent to the trading request. To solve this issue, I had to specify correct data corresponding to the appropriate symbol specification directly in the trading request

This required the knowledge of a symbol specification and the manual input of accurate values directly in the program code instead of auto correction of values by the library itself. To simplify things, we are going to make minor changes in the trading class handling logic. All symbol trading objects are to be initialized by auto selection of correct values in the EA's OnInit() handler. The -1 values are passed to the trading methods of the trading class by default for order filling and expiration types indicating it is time to use preset correct default values. If another value is passed from the program, it is applied instead. If the value turns out to be invalid, it is corrected when handling errors in the trading class.

Author: Artyom Trishkin