Discussion of article "MQL5 Cookbook: Indicator Subwindow Controls - Buttons" - page 4

 
DC2008:

And the fact that "button functions are placed in the OnInit function" is very funny!

However, maybe you don't understand what we are talking about? If you press a button, some user function should be triggered, which will perform some micro-task.

 
DC2008:

All right, let's have a laugh. The article was written by you, "nobody pulled your tongue".

So, the explanation in the form of quotations for the unexplainable is at least disrespectful to your readers. Questions should be answered with examples and links to primary sources.

Confusing and overloaded code with unnecessary functions only misleads "beginners".

And the fact that "button functions are placed in the OnInit function" is very funny!

Nobody pulled you by your tongue. Are you going to give me proofs? Or rather, a refutation of my statement? For your information, not everything is described in the Handbook yet. I mean, work on the handbook is in progress, additions and corrections are being made. You should always check everything yourself.

Believe me, the code from your article is much more "confusing" for beginners and not only, which can be seen in the discussion of your article.

However, maybe you do not understand what we are talking about? If you click on a button, some user function should be triggered to perform some micro-task.

Yes, I took it literally. Ask your questions more precisely. But I anticipate that my answer will be ridiculed by you, since you seem to have such a function today.

In this case the "microtask" was to change the colour of the button. I purposely didn't add any extra features so as not to have anything superfluous. Just to avoid overloading the code.

Actually, the topic of the article is not limited only to buttons. Most of it is about chart events. There are few such examples, so I decided to write one.

 

Dear author of the article, you wrote it not for me, but for beginners. Indeed, I am not interested in your solutions, but we are talking about those who are just getting to know the language. What "other programs" are we talking about? And how can the OnDeinit function of one program affect the functions of other programs?

We are discussing an article and what are you so indignant about?

Try to answer the questions not for me, but for beginners - so that they understand why and how.

Документация по MQL5: Основы языка / Функции / Функции обработки событий
Документация по MQL5: Основы языка / Функции / Функции обработки событий
  • www.mql5.com
Основы языка / Функции / Функции обработки событий - Документация по MQL5
 
DC2008:

Dear author of the article, you did not write it for me, but for beginners.

Exactly so.

Indeed, I am not interested in your solutions, but we are talking about those who are just getting to know the language.

But you ask questions.

What "other programmes" are we talking about?

The very ones you gave links to before. And you try to refute my statement by hints without giving a proof.

And how can the OnDeinit function of one program affect the functions of other programs?

It does. I wrote about it. The editor who published the article confirmed it. You can also check it and see for yourself.

We are discussing the article and what do you resent so much?

Nothing. I'm waiting for a rebuttal to my assertion. )

Try to answer questions not for me, but for newcomers - so that they understand why and how.

There have been no questions from newcomers so far. And there can be no questions. Everything is very clear and every line of code is commented in detail.

 

We jam this first:

void OnTimer()
  {
//--- Check if mouse event tracking is enabled
   //CheckChartEventMouseMove();

  }

i.e. now we don't track mouse events, right?

Run your code on the chart:

now we run "another programme", let it be your code again:

I guess something went wrong? Or is that what we're supposed to do?

now we delete one of the indicators and according to the author of the code we have lost "mouse tracking", but it does not happen:

 
C-4:

If you don't qualify, then I don't know who does? Danald Knuth? Bill Gates?

I was just trying to get a compliment. It worked.)

C-4:
I see. But what is not clear is that the leading products of the Market created by you do not belong to you. Isn't that a shame?

1. It's not evening yet)

2. My handicraft is also constantly in the top, although it is not in any comparison with the panel.

3. The success of the panel is largely due to the efforts of the author of the idea, so it is incorrect to say that it is my product.

4. I did not work for free)

 
DC2008:

...

now we delete one of the indicators and according to the author of the code we have lost "mouse tracking", but this does not happen:

Now check if the OnDeinit() event is triggered in the indicators. This is the interesting point I mentioned before. :) Namely in OnDeinit(), in the example from the article, the motion tracking event is disabled. Since some build it seems that OnDeinit() has stopped working in indicators at all. This is a bug and we should inform the developers.

Further, to make sure that my statement is correct, we need to make a blank Expert Advisor (the OnDeinit() function works in Expert Advisors), in which it is enough to add this line of code (highlighted):

//+------------------------------------------------------------------+
//|TEST.mq5 |
//| Copyright 2013, MetaQuotes Software Corp. | |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Deinitialisation function of the expert |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- Disable mouse event tracking
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,false);
  }
//+------------------------------------------------------------------+
//| OnTick|
//+------------------------------------------------------------------+
void OnTick()
  {
  }
//+------------------------------------------------------------------+

//---

And now, if you remove the Expert Advisor when the indicator from the article is on the chart, the tracking of the movement event will be disabled in the indicator as well.

About this one:

something must have gone wrong? Or is this the way it is designed?

It is known. It is not designed that way, it is just not taken into account in this article. The article, as always, is a simple example, not a ready-made solution for all cases. )

 
Sergey, don't make a fuss. For example, it was not clear to me why to use a timer. But in a couple of moments I found an explanation in the article and immediately understood everything. I have not checked this statement in practice, but in this I trust the author, realising that he wrote it for a reason, and if the timer was introduced, there were reasons for it.
 
void OnDeinit(const int reason)
  {
//--- Disable mouse event tracking
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,false);
  }

In general, this code seems to be very problematic. There is no real reason to switch off mouse movement tracking when disabling the Expert Advisor/indicator. If you want to bother so much, you should restore the state that existed before the Expert Advisor was initiated:

bool mouseStatus;
void OnInit()
  {
  mouseStatus = ChartGetInteger(0,CHART_EVENT_MOUSE_MOVE);
  }

void OnDeinit(const int reason)
  {
   //--- Disable mouse event tracking
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,mauseStatus);
  }
 
C-4:

In general, this code seems to be quite problematic. There is no real reason to switch off mouse movement tracking when disabling the Expert Advisor/indicator.

No, you are wrong. There are real reasons to disable mouse tracking. And I will prove it now. )

For example, you have two programs running on a chart. The Expert Advisor, in which you need to track the mouse movement event. And an indicator in which you do not need to track the mouse movement event, but you need to track some other chart events.

Now run this code of the Expert Advisor:

#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Enable mouse event tracking
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Deinitialisation function of the expert |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- Disable mouse event tracking
   //ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,false);
  }
//+------------------------------------------------------------------+
//| OnTick|
//+------------------------------------------------------------------+
void OnTick()
  {
  }
//+------------------------------------------------------------------+
//| ChartEvent function|
//+------------------------------------------------------------------+
void OnChartEvent(const int    id,
                  const long   &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//--- Tracking mouse movement and left mouse button presses
   if(id==CHARTEVENT_MOUSE_MOVE)
     {
      static int count=1;
      Print("CHARTEVENT_MOUSE_MOVE; EXPERT; ",count);
      count++;
     }
  }
//+------------------------------------------------------------------+

In it, during initialisation, in the OnInit() function, tracking of the mouse movement event is enabled. But the line in the OnDeinit() function, where this tracking should be disabled, is intentionally commented out.

Load the indicator on the chart as well. Here is its code:

#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Deinitialisation function of the expert |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function|
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//--- Tracking mouse movement and left mouse button presses
   if(id==CHARTEVENT_MOUSE_MOVE)
     {
      static long count=1;
      Print("CHARTEVENT_MOUSE_MOVE; INDICATOR; ",count);
      count++;
     }
  }
//+------------------------------------------------------------------+

Both the first and the second programme prints a message to the log that the event is received. Now remove the Expert Advisor from the chart. Let's assume that you have made some calculations with its help and you don't need it anymore. After its removal, since the mouse movement tracking event has not been disabled, the indicator continues to receive this event. And you don't need it.

Do you agree now? )