Discussion of article "Library for easy and quick development of MetaTrader programs (part XXIII): Base trading class - verification of valid parameters"

 

New article Library for easy and quick development of MetaTrader programs (part XXIII): Base trading class - verification of valid parameters has been published:

In the article, we continue the development of the trading class by implementing the control over incorrect trading order parameter values and voicing trading events.

Compile the EA and launch it in the tester, while preliminarily setting Lots to 10, as well as StopLoss in points and TakeProfit in points to 1 point each in the parameters:


Thus, we attempt to open a position with an invalid lot size, so that the funds for opening it are insufficient, and try violating the minimum stop order distance regulated by symbol's StopLevel parameter:


The EA displays two errors in the journal — "Not enough money to perform trading operation" and "StopLoss values violate the StopLevel parameter requirements". We have also set TakeProfit to one point. Why does the EA display no info of that error as well? Actually, there is no error here since placing TakeProfit and StopLoss levels performed within the minimum SYMBOL_TRADE_STOPS_LEVEL does not violate the rule:

TakeProfit and StopLoss levels should be compared to the current price for performing the opposite operation

  • Buying is done at the Ask price — the TakeProfit and StopLoss levels should be compared to the Bid price.
  • Selling is done at the Bid price — the TakeProfit and StopLoss levels should be compared to the Ask price.

Author: Artyom Trishkin

 

Well, thank you. For MQL4 this is really a find. Thank you for your hard work and time spent for the benefit of the community.

Let's start writing documentation already.

 
Alexey Viktorov:

Well, thank you. For MQL4 this is really a find. Thanks for your hard work and time spent for the benefit of the community.

Let's start writing documentation already.

Detailed documentation will be available only after the main functionality of the library is developed. So for now you can ask questions in the discussions of the articles.
 

I am curious - does anyone use these libraries? They are really huge sheets of code and it will take more time to understand them than to study MQL itself. It is very possible that the library is useful to use. But in my opinion, there are fewer operators in mql5 than methods and classes in this huge library.

In my opinion, OOP should reduce the code and make it more readable. But using all these libraries, I have not noticed any convenience. If you take the standard library, there to open a position there is used a simple contsrution : Obligated object of the type:

Ctrade tr;
tr.OpenBuy();

that's it!

But with this library only OnInit is stuffed with a lot of things. So many global variables are used. It is problematic to find something, to put it mildly.

 
Dmitiry Ananiev:

I am curious - does anyone use these libraries? They are really huge sheets of code and it will take more time to understand them than to study MQL itself. It is very possible that the library is useful to use. But in my opinion, there are fewer operators in mql5 than methods and classes in this huge library.

In my opinion, OOP should reduce the code and make it more readable. But using all these libraries, I have not noticed any convenience. If you take the standard library, there to open a position there is used a simple contsruktion : Obligated object type:

Ctrade tr;
tr.OpenBuy();

that's it!

And with this library, only OnInit is stuffed with a lot of stuff. So many global variables are also used. It is, to put it mildly, problematic to find something.

Yes, they do.

You don't need to parse the library code. The articles describe the creation process and serve as a detailed tutorial for those who are interested.

Each article is accompanied by a test advisor, which shows how to use this or that functionality of the library. If the functionality is not required, it does not need to be initialised.

The library is not finished - it is only being developed. There will be simple and convenient functions for accessing data and for opening a position. By the way, you described opening a position with default values. And you skipped (on purpose?) the initialisation of the trade object.

If there is no simple Buy(), Sell() method in the library at the moment, it doesn't mean that there won't be any in the future. There will be, and not only them.

And now, please, show me, for example, how you can easily identify a closed position in MQL4, the previous one, with magik 123 and not the current symbol - whether it was opened when a pending order was triggered. And what kind of order.

 
Artyom Trishkin:

whether it was opened when the pending order was triggered. And what kind of order.

MQL4 does not store the history of triggered pending orders, you can only determine in the history of orders:

- if the closed order was of OP_BUY or OP_SELL type - it means that a market order was closed.

- if the closed order was of OP_BUYLIMIT, OP_BUYSTOP, OP_SELLLIMIT or OP_SELLSTOP type - it means that the pending order was cancelled.


The time of order closing corresponds to the time of market order closing or the time of pending order cancellation.

Time of opening of the pending order corresponds to the time of placing the pending order, but this time will be replaced at the moment of triggering of the pending order by the time of opening of the market order.

Ticket and magick number of the order does not change during the whole time (except for the case of counter or partial closing of the order - there is a different situation, but the magick does not change).


I.e. the fact of pending order triggering is not present in the history of MQL4 orders, there is only the fact of pending order cancellation. I don't even remember how necessary this information is, perhaps I don't know all the tasks involved.

 
Igor Makanu:

How much of this is necessary information - I don't even recall, perhaps the tasks are not all I know

Estimation of slippage value. In MT5 there are OrderOpenPriceRequest and OrderClosePriceRequest for this purpose.

 
Igor Makanu:

MQL4 does not store the history of triggered pending orders, you can only define in the history of orders:

- if the closed order was of OP_BUY or OP_SELL type - it means a market order was closed

- if the closed order was of OP_BUYLIMIT, OP_BUYSTOP, OP_SELLLIMIT or OP_SELLSTOP type - it means that the pending order was cancelled.


The time of order closing corresponds to the time of market order closing or the time of pending order cancellation.

Time of opening of the pending order corresponds to the time of placing the pending order, but this time will be replaced at the moment of triggering of the pending order by the time of opening of the market order.

Ticket and magick number of the order does not change for the whole time (except for the case of counter or partial closing of the order - there is a different situation, but the magick does not change).


I.e. the fact of pending order triggering is not present in the history of MQL4 orders, there is only the fact of pending order cancellation. I don't even remember how necessary this information is, perhaps I don't know all the tasks involved.

So I asked a person who doesn't understand the library's capabilities to write how he "easily and simply" recognises it.

And the library can. And the user doesn't even have to think about it - just ask.

It's immediately clear about him - "I haven't read it, but I condemn it".

 
fxsaber:

Estimation of slippage value. MT5 has OrderOpenPriceRequest and OrderClosePriceRequest for this purpose.

I haven't evaluated it yet, because I'm stuck on creating perfection...rewriting rewritten - rewritten ((((

but imho, such things (evaluation of broker's work) should be done in parallel with the work of the main Expert Advisor and logged, such data has no sense in the tester?


-------------------

Artyom Trishkin:

So I asked a person who doesn't understand the library's capabilities to write how he "easily and simply" recognises it.

And the library can. And the user doesn't even have to think about it - just ask.

It's immediately clear about him - "I haven't read it, but I condemn it".

on the materials of the article, I leaf through selectively, the amount of information is just too large, so it's easier to ask:

Is it possible to save the state of the TS in the test examples? - I am not interested in "picking up" orders on my own magik, I am interested in realisation of saving the state of the Expert Advisor in case of terminal reloading.

 
Igor Makanu:

such data is meaningless in a tester?

It makes a lot of sense in a tester. You can be very deceived if you don't estimate slippage.

For example, I noticed this situation right away

Forum on trading, automated trading systems and testing trading strategies.

MetaTrader 5 Strategy Tester: errors, bugs, suggestions for improving its work

fxsaber, 2019.10.13 16:58

On stock custom symbols, take-outs are accepted at last-price and executed at bid/ask.

For example, the take for a BUY position is at 1.09801. The bid/ask/last tick = 1.09799/1.09802/1.09801. It triggers because the last price has been touched, but it triggers at the bid price, which is worse than last.

It turns out that the takes are triggered all the time with negative slippage.

I do nothing without Report-bid in the Tester. Otherwise, you can do nonsense for a long time and not notice it.
 
Igor Makanu:
...

on the materials of the article, I leaf through selectively, the volume of information, well, just big, so it is easier to ask:

Does the test examples provide for the possibility of saving the state of the TC ? - I am not interested in "picking up" orders on my own magik, I am interested in realisation of saving the state of the Expert Advisor in case of terminal reloading.

The test examples provide only for checking what is described in this particular article. As a test of operability.

Examples of using the functionality together with its description will be in separate articles after the completion of the main library functionality and creation of user functions for quick access to all library features.

----------------------

What is meant by "expert state"?