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

 
tol64:

Not necessarily every second, there is an alternative on another event there (already discussed). Please give me an example of how I did it here. ) From the condition that the Expert Advisor needs this event, but the indicator does not. It will be clearer that way.

P.S. Correction. I made a mistake. )) Your variant is not more correct. It doesn't fit at all. So it is better to give an example based on the condition above.

If the indicator does not need this event, it simply does not process it. Also, the Expert Advisor should not disable events it does not need. It can switch them on, but not switch them off. Because it is none of his business what events pass through his window and who may need them.

 
C-4:

If the indicator does not need this event, it simply does not process it. Also, the Expert Advisor should not disable events that it does not need. He can switch them on, but not switch them off. Because it is none of his business what events pass through his window and who may need them.

The point is that this event can be unprocessed (just forget about it). But this does not mean that the event queue in the OnChartEvent() function will not be filled with things that are not needed at a certain moment.

And this means thousands of unnecessary events per minute. And if there are several programmes on the chart? Not an argument?

Much less resources are wasted if you even make a check every second to see if an event is enabled, and enable it if it is not currently enabled but is needed. Not an argument either? Then do it your way.

I don't have any more arguments. ) I'll stand by my opinion, as I haven't heard anything that can change my mind.

Good. Then I have a question for those who think that this event doesn't need to be disabled by the programme that enabled it.

Why? )

That is:

1. Why leave something that is not needed (thousands of events per minute) ?

2. (in another formulation) Why spend more resources when you can spend less ?

Options like, "if an event is not needed, just don't process it" I personally don't like at all. You can't disable one, you can't disable the other, and what will you get out of it?

 

Dear author of the article, you are in vain not to explain the internal contradictions of your products, which you are trying to fight and teach "beginners".

So, the author has shown the slippery moments that can upset the correct work of his indicator. Great, now it is clear to the "beginner" that:

  1. When deleting any programme from the chart, you should think about not harming other programmes.
  2. In no case you should not place conflicting programmes on one chart, but it is better to place them in other windows of the chart of the symbol in question. If anyone does not know this, then one symbol can open a sufficient number of chart windows.
  3. Each chart has its own inherent properties. Therefore, by changing them, you can disturb the correct work of other programmes. Under no circumstances should this be done!
  4. There must be "fool-proof". That is, if a virus in the form of an indicator or another programme tries to change the properties of a chart that you use in your programs, you must check it. And if it happens regularly - remove the virus!
  5. Errors in programs for financial markets most often lead to huge losses. Remember about it!
 
tol64:

1. Why leave what is not needed (thousands of events per minute) ?

2. (in another formulation) Why spend more resources when you can spend less ?

Options like, "if an event is not needed, just don't process it" I personally don't like at all. You can't disable one, you can't disable the other and what will you get out of it?

You will get a completely controlled code.

You emphasise performance, but does it fall so much with this enabled event? To answer this question, I have specially written a simple Expert Advisor testing this event. Having tested different combinations, I got the following table:

Mode
% CPU load
EVENT_MOVE_MOUSE is enabled, processing of this event in the Expert Advisor is enabled.9%
EVENT_MOVE_MOUSE is enabled, processing of this event in the Expert Advisor is disabled.
6%
EVENT_MOVE_MOUSE is switched off, processing of this event in the Expert Advisor is switched off.
5-6%
The Expert Advisor is switched off. The chart is closed. Just move the mouse over the MetaTrader window.
5-6%

As you can see, the real load increases only when the actual processing of this event takes place. It is noteworthy that judging by the CPU load, MetaTrader tracks the mouse position regardless of whether the subscription to this event is enabled or not. In general, it turns out that it is pointless to save hypothetical resources, because mouse tracking will be performed anyway.

Test Expert Advisor code:

//+------------------------------------------------------------------+
//|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"
//+------------------------------------------------------------------+
//| Expert initialisation function|
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ObjectCreate(0, "Edit", OBJ_EDIT, 0, 0, 0);
   ObjectSetInteger(0, "Edit", OBJPROP_XSIZE, 400);
   //Turn the event on and off as we see fit
   ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, false);
   
//---
   return(INIT_SUCCEEDED);
  }
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   //Comment the block if it is not necessary to process the incoming event.
   if(id == CHARTEVENT_MOUSE_MOVE)
   {
      string label = (string)lparam + " " + (string)dparam + " " + sparam;
      //printf(sparam);
      ObjectSetString(0, "Edit", OBJPROP_TEXT, label);
      ChartRedraw(0);
   }
}
Знакомство с MQL5: написание простого советника и индикатора
Знакомство с MQL5: написание простого советника и индикатора
  • 2010.03.16
  • Denis Zyatkevich
  • www.mql5.com
В этой статье проведен краткий обзор языка MQL5, приведен пример написания советника и индикатора. Данная статья ориентирована как на читателей, знакомых с программированием на языке MQL4, так и на тех, кто только начинает знакомство с программированием торговых систем и индикаторов.
 

1. You should always consider the case that an event is missed on the stack. If something critical can happen in the case where an event is missed, it is very bad.

2. Customising the chart to suit yourself is bad. It is about the same as trading an automated trading machine without a magik.

 
DC2008:

Dear author of the article, you are in vain not to explain the internal contradictions of your products, which you are trying to fight and teach "beginners".

So, the author has shown the slippery moments that can upset the correct work of his indicator. Great, now it is clear to a "beginner" that:

...

You can come up with 20 more rules to justify your sense of self-importance and then you will definitely confuse yourself and "help" beginners. Contradictions and misunderstandings in this case were observed by you. )

C-4:

You will get a fully controlled code.

...

It will be controlled when you control it. In this case, you propose to let everything go unchecked, i.e. to leave an event that is not needed at the moment and can be reproduced very often. On simple examples it may not be noticeable. Perhaps you will see the need to disable everything that is not needed in more complex programmes.

 
TheXpert:

1. You should always consider the case that an event is missed on the stack. If something critical can happen in the case where an event is missed, it is very bad.

...

Like when the event queue overflows, for example?
 

tol64:

Excuse me, am I distracting you by any chance from writing another tutorial or recipe?

If not, let's continue discussing your article about control in the indicator subwindow. So, you offer a mass solution (or an idea) how to make a convenient menu in an indicator. Good, the purpose of the article is very worthy! But how can a "beginner" programmer use all this arsenal? Where to place custom functions? Demonstrate it by example. And at the same time explain what you need to fix in the code to use, for example, 5 buttons? Consider it a beginner's question.

 
tol64:
Like when the event queue overflows?
Yeah.
 
DC2008:
Are you so sure everything in your article is perfect?