Discussion of article "Library for easy and quick development of MetaTrader programs (part XXII): Trading classes - Base trading class, verification of limitations"

 

New article Library for easy and quick development of MetaTrader programs (part XXII): Trading classes - Base trading class, verification of limitations has been published:

In this article, we will start the development of the library base trading class and add the initial verification of permissions to conduct trading operations to its first version. Besides, we will slightly expand the features and content of the base trading class.

To check the work of the methods checking trading limitations, we need to artificially create them.
For example:

  1. disable Internet access (to simulate the loss of connection to the trade server),
  2. disable trading in the EA settings (press F7 and uncheck "Allow Automated Trading" in the Common tab of the EA settings window),
  3. disable auto trading in the terminal (the AutoTrading button).

Click the position opening button in the EA trading panel. The following entry appears in the journal:

2019.09.26 15:07:55.582 CTrading::OpenBuy: Request rejected before being sent to server due to:
2019.09.26 15:07:55.582 1. No permission to conduct trading operations in terminal ("AutoTrading" button disabled)
2019.09.26 15:07:55.582 2. No connection to trade server
2019.09.26 15:07:55.582 3. EA does not have permission to conduct trading operations (F7 --> Common --> "Allow Automatic Trading")

Let's eliminate the restrictions one by one.

After enabling the Internet connection, we obtain the following message when attempting to open a position:

2019.09.26 15:10:36.766 CTrading::OpenBuy: Request rejected before being sent to server due to:
2019.09.26 15:10:36.766 1. No permission to conduct trading operations in terminal ("AutoTrading" button disabled)
2019.09.26 15:10:36.766 2. EA does not have permission to conduct trading operations (F7 --> Common --> "Allow Automatic Trading")

Enable auto trading in the terminal clicking the AutoTrading button. When attempting to open a position, we obtain the following:

2019.09.26 15:13:03.424 CTrading::OpenBuy: Request rejected before being sent to server due to:
2019.09.26 15:13:03.424 EA does not have permission to conduct trading operations (F7 --> Common --> "Allow Automatic Trading")

Press F7 and allow the EA to trade in its settings. When attempting to open a position, we are finally successful:

2019.09.26 15:14:32.619 - Position is open: 2019.09.26 11:14:32.711 -
2019.09.26 15:14:32.619 EURUSD Opened 0.10 Buy #455179802 [0.10 Market-order Buy #455179802] at price 1.09441, Magic number 123

Other limitations can be checked in the tester or a demo account by creating a situation when one of the limitations is activated, for example, a limitation by the maximum number of pending orders on the account.

Author: Artyom Trishkin