Very good article, I protect programmes from such vandalism in a slightly different way ...
I create all necessary objects with a prefix outside the chart visibility in a special function like CREATE_OBJECTS(),
then I check error 4202 ERR_OBJECT_DOES_NOT_EXIST Object does not exist, and if there is such an error, I call the CREATE_OBJECTS() function again.
The rest of the object properties are changed as needed in the chart.
Well done. The article is good. The examples are not bad.
But there seems to be a simple way to check the existence of an object and you can always restore it if necessary.
But there seems to be a simple way to check the existence of an object and it can always be restored if necessary.
Thank you all for the feedback!
Well done. The article is good. The examples are not bad.
But there seems to be a simple way to check the existence of an object and you can always restore it if necessary.
Thank you, Victor!
Just in case, I will say that the given variants are not in opposition to the usual habitual ways (simple or not so simple).
It's just that the usual familiar ways (simple or not so simple) may not always be "timely". Especially since the same various "naughty hands" have not been cancelled. Including, and perhaps in some cases our own or user's.
That is, if, for example, the objects of the control panel of the programme are accidentally deleted through the "Objects List" together with other selections via Shift or by a third-party programme, where the function for deleting objects(ObjectsDeleteAll() or created independently) can be used, which performs according to the parameters set in it:
.
- total deletion of all types of graphical objects in the same window/subwindow where objects created manually or with the help of other programmes are located;
- or total deletion of objects of the type that are also present in the control panel of your programme;
- or deletion by a prefix that coincides with the prefix of objects in your programme,
then the options described in this article may come in handy, responding to the situation as it arises. Including, in some cases, freeing you from some unnecessary "movements" of your own. These options, I believe, can be referred to universal and, if necessary, they can be combined with others "painlessly and without conflict".
Somehow.
I.e., for "protection" of programme objects, of course, different options, methods and their combinations can be applied.
And the ones described in the article are not some mandatory for every code, but those that may be not superfluous in some cases.
The trick is to reduce the number of checks to a minimum instead of checks without breaks. For this purpose they are tied to a specific event. If I understood correctly.
Yes, thanks, that's right, reducing the number of processing during checks is one of the chips there.
This article is totally obsolete.
1. It´s definitely not for beginners
2. It´s not MQL5 - it is MQL4!
3. The way of coding is totally complicated and - in view of MQL5 - totally wrong anyway.
If one thinks it´s a problem, that another EA or indicator could destroy objects, this can be done much more efficient and elegant:
- Define an MQL object for each chart object, such as the standard Control library already does. Each such MQL object represents a chart object and holds all it´s data - normal MQL5 style.
- Pack all the objects into a master container
- Only the master container checks, if a chart object has been deleted, either from time to time or by the corresponding chart-event during OnChartEvent().
- Add a .ReCreate() member function to CWnd, and an OnRecreate() virtual function to all objects which implement this functionality
- If the master container detects kind of "vandalism", it sends a .ReCreate() to all it´s child objects
Done.
I've got little understanding of English. I didn't read the version of this article in English.
Sorry, but... did you read this article in its entirety?
Do you speak Russian?
If you speak Russian, then you and I can talk more constructively at the discussion at the Russian version of this article.
This article is totally obsolete.
You are wrong.
1. It´s definitely not for beginners
Why do you think so? Tell me this, please, in more details.
2. It´s not MQL5 - it is MQL4!
You are wrong.
But the schemes described in this article can be used not only for MQL5, but and for MQL4.
3. The way of coding is totally complicated and - in view of MQL5 - totally wrong anyway.
Пожалуйста прочитайте эту статью "MQL5 для начинающих: Антивандальная защита графических объектов" ещё раз внимательно. И пожалуйста не торопитесь с выводами. Если и после этого ваше мнение не изменится, то напишите более конкретно непонятные для вас моменты.
Please read this article "MQL5 for beginners: Anti-vandal protection of graphic objects" again carefully. And please do not rush to conclusions. If after this will not change your opinion, write more particularly difficult moments for you.
If one thinks it´s a problem, that another EA or indicator could destroy objects, this can be done much more efficient and elegant:
- Define an MQL object for each chart object, such as the standard Control library already does. Each such MQL object represents a chart object and holds all it´s data - normal MQL5 style.
- Pack all the objects into a master container
- Only the master container checks, if a chart object has been deleted, either from time to time or by the corresponding chart-event during OnChartEvent().
- Add a .ReCreate() member function to CWnd, and an OnRecreate() virtual function to all objects which implement this functionality
- If the master container detects kind of "vandalism", it sends a .ReCreate() to all it´s child objects
Done.
В статье "MQL5 для начинающих: Антивандальная защита графических объектов" рассматриваются схемы только двух вариантов (способов) из множества возможных. Но различных вариантов (способов) конечно может быть много.
Применять или не применять схемы из этой статьи - это зависит только от ваших решений.
Скажу только, что эти две схемы из статьи "MQL5 для начинающих: Антивандальная защита графических объектов" обладают следующими положительными качествами:
- экономно используют ресурсы компьютера и торгового терминала;
- имеют высокий уровень своевременности срабатывания (не все другие обычные привычные способы могут быть своевременными);
- могут быть применены совместно со многими другими вариантами (способами).
Эти схемы из данной статьи сконструированы в процедурном стиле. В том числе, чтобы они были более понятны, наглядны и могли послужить идеями для каких-то других вариантов.
Если вам не нравятся эти схемы или они не подходят вам по каким-то другим причинам, вы конечно можете использовать другие схемы. И, естественно, в том стиле программирования, что для вас привычен.
Применять эти схемы из статьи или не применять - это ваше личное дело и право.
In the article "MQL5 for beginners: Anti-vandal protection of graphic objects" are considered only two options schemes (methods) of many possible. But the options (methods) can be a lot.
To use or not to use the schemes from this article - it just depends your decisions.
I can only say that these two schemes from the article "MQL5 for beginners: Anti-vandal protection of graphic objects" have the following positive qualities:
- economical use resources of the computer and the trading terminal;
- have a high level of timeliness of response (not all the other usual habitual ways can be timely);
- they may be used in conjunction with many other ways.
These schemes this article were made in a procedural style. In particular, to make them more understandable, visible and could serve as ideas for some other options.
If you do not like these schemes or they do not fit you for some other reason, you can of course use other schemes. And, of course, in the style of programming that you like.
To use or not to use the schemes from this article - it depends your decisions.
Sorry for my English.
P./S.: Пожалуйста прочитайте эту статью ещё раз внимательно. И пожалуйста не торопитесь с выводами. Если у вас затем будут конструктивные вопросы или предложения, то пишите, пожалуйста. Я смогу ответить вам скорее всего только после новогодних каникул. Это через пять дней.
Please read this article again carefully. And please do not rush to conclusions. If you will have any specific questions and suggestions, please write. I can answer you will probably only after the New Year holidays. It is in five days.
P./S.: Сегодня у нас праздник Нового года. Поэтому и вас поздравляю с наступающим новым 2016-м годом!
Today we have the New Year holiday. Therefore you Happy New 2016 Year!
When compiling in MetaEditor Version 5.00 build 1241 the test codes attached to the article with the names:
- test_count_click_0.mq5
- test_count_click_1.mq5
- test_count_click_2.mq5
As before, they work correctly as far as anti-vandal functions are concerned. However, when compiling in the new build, I found a problem with a function that does not belong to the anti-vandal measures from the article. I made a request to Service Desk (#1379624), but it's a holiday, so naturally I don't expect to get an answer or a solution from there.
Below is the description of the problem, the way of its solution and files with the solution of the problem, instead of attached to the article:
But first I would like to emphasise again that the functions related to vandalism worked and work correctly when compiling in the new build.
The incorrectness of the named test codes is manifested in the fact that when clicking on the control panel objects of these test codes, the number of clicks is no longer displayed, except for the very first ones. That is, no matter how many buttons are clicked, the numbers will be the same:
However, these same test codes, compiled in earlier versions, continue to work correctly in the new 1241 build, if they are not compiled there. That is, when clicking on the objects of these test codes there is a normal counting of clicks:
Ifound out that the detected problem is related to the application of the ArrayFill() function in the CHARTEVENT_OBJECT_CLICK event processing block in OnChartEvent().
count=countClick[index]+count;
int summ=countClick[NUMBER_ALL]+1;
//---
ArrayFill(countClick,index,1,count);
ArrayFill(countClick,NUMBER_ALL,1,summ)
However, if you put data printout or ChartRedraw() before this function, the named codes from the article start working correctly after compilation:
count=countClick[index]+count; int summ=countClick[NUMBER_ALL]+1; //--- //TEST_PRINT_TWO(count,summ); ChartRedraw(); //--- ArrayFill(countClick,index,1,count); ArrayFill(countClick,NUMBER_ALL,1,summ);
In the three files with fixes attached below, as well as in their versions of the same name attached to the article, these sections, as well as fixing the problem in the codes below, are identical. That is:
- in the file test_count_click_0.mq5 - anti-vandal protection measures are not applied;
- in the file test_count_click_1.mq5 - a variant of "self-deletion" of the program from the chart in case of unauthorised interference with its objects on the chart;
- in the file test_count_click_2.mq5 - a variant of "self-recovery" of the program objects in case of their unauthorised modification or deletion.
P./S.: For correct work of the attached codes below it is required to have in the folder "Include" the file objectcreateandset.mqh, attached to the article, where the codes, on the basis of which I found the incorrect work of the named function, are attached. Also this file can be downloaded from Code Base
For example, it may be useful to get acquainted with the check filters based on the StringFind() function in the example schemes of the article. Because filters with the help of this function, if necessary, can significantly minimise the number of searches of object names when notifications about any events with objects in the chart are received in the programs where they are applied. That is, they can be useful, if necessary, not only when constructing any anti-vandal variants. And I will add, just in case, that the scope of application of check filters based on this function can be extended, if necessary, by using its third input parameter.
- Define an MQL object for each chart object, such as the standard Control library already does. Each such MQL object represents a chart object and holds all it´s data - normal MQL5 style.
- Pack all the objects into a master container
- Only the master container checks, if a chart object has been deleted, either from time to time or by the corresponding chart-event during OnChartEvent().
- Add a .ReCreate() member function to CWnd, and an OnRecreate() virtual function to all objects which implement this functionality
- If the master container detects kind of "vandalism", it sends a .ReCreate() to all it´s child objects
Your solution: buy a new OOP-suit. Oh, and also don't forget to buy a tie for your new suit
PS As for Standard Library: unfortunately Control library is the worst part of this library - too many bugs & unrealised or unaccessible options. As result - sometimes this library is a source of problems (garbage on chart), referred in this article

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article MQL5 for beginners: Anti-vandal protection of graphic objects has been published:
What should your program do, if graphic control panels have been removed or modified by someone else? In this article we will show you how not to have "ownerless" objects on the chart, and how not to lose control over them in cases of renaming or deleting programmatically created objects after the application is deleted.
One of the advantages of the MQL5 programming language is that with the existing MQL5 standard functions you can form codes for completing various tasks and achieving different goals when using the MetaTrader 5 trading terminal.
This article, written in a simple language and containing easy examples, considers two variants of implementing program's response actions to the control panel's graphic objects being deleted or changed. We are going to reveal how you can ensure that after the program is deleted, there are no ownerless objects present on the chart, over which the program may have lost control, because somebody or something has renamed them.
Fig. 1. Example of a control panel's appearance before and after its object's properties have been manually changed
Options for constructing the response actions to external interference in the code, described in this article, may not be redundant for those cases where, for example, a third-party program launched on the chart and not directly intended for its cleanup, uses a function for deleting objects (ObjectsDeleteAll () or the one you create yourself), operating by the parameters set in it:
These options are also relevant, when it is advisable, including for the program's correct operation, to provide actions for accidental or intentional removal of its control panel's objects or manual change of their properties in the code.
This article can also be helpful for those who just started learning the event handling in the OnChartEvent() function.
Author: Dina Paches