Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1594

 
MrBrooklin #:
How would you briefly characterise the word handle?
Number)
 
Aleksei Stepanenko #:
Number)

I see. ) But seriously? Here is taken from the documentation:

iMA

Возвращает хэндл индикатора скользящего среднего. Всего один буфер.

int  iMA( 
   string               symbol,            // character name 
   ENUM_TIMEFRAMES      period,            // period 
   int                  ma_period,         // averaging period 
   int                  ma_shift,          // indicator offset horizontally 
   ENUM_MA_METHOD       ma_method,         // smoothing type 
   ENUM_APPLIED_PRICE   applied_price      // price type or handle 
   );
 

Alexei, based on your definition of handle, it appears that iMA returns the number of the moving average indicator? )) Abracadabra, that's all.... )

Regards, Vladimir.

 

Vladimir, roughly speaking, you can consider the handle as a line number of the list, which contains addresses of memory cells, starting from which executable codes of calculation of all necessary indicators are stored. Since there are many different indicators, there is no sense to always add all of them to this list. It is filled according to the requests of the author of a particular Expert Advisor. If you need some indicator, you should add it to this list and place its code somewhere in memory.

Calling functions like iMA just adds a new item to this list. That is, if you need to get the calculations of this indicator in the programme, you need to refer to the memory address, which is under the next number. This new number in the list is returned by those functions, which are written about that they return the handle.

Well, what is a number in the list if not a number?

 
Yuriy Bykov Calling functions like iMA just adds a new item to this list. That is, if you need to get the calculations of this indicator in the programme, you need to refer to the memory address, which is under the next number. This new number in the list is returned by those functions, about which it is written that they return the handle.

Well, what is a number in the list if not a number?

Yuri, you are right as well as Alexey. Now I put the first handles of iMA, iTEMA and iDEMA indicators one after another in a test EA, and then I ran them step by step from the stop point set on iMA. I got the return of values from iMA - 10, from iTEMA - 11 and iDEMA - 12. Then, no matter how I rearranged the handles of these indicators, they still consistently gave values 10, 11 and 12.

Your explanation, Yuri, has become more or less clear to me. Thank you! Now I just need to understand the smallest thing - why the numbering of handles starts not from zero but from 10? )

Regards, Vladimir.

 

Vladimir, do you really need to understand it so much?

In the programming world, and in the world in general, we use a lot of things without thorough understanding of all the internal nuances of their work. We trust the developers of these things, believing that the decisions they made to implement something in this way and not in another way had some grounds.

I didn't have to participate in the work on the MQL5 compiler and language, so I can't say exactly why the numbering of handles starts with 10. I can guess why it is so, but it doesn't make much sense. After all, in the code we will not use handles as numbers to perform any arithmetic operations. Therefore, only two things are important for us, as MQL5 users:

  • Uniqueness - for different indicators the handles received and remembered in our programme will have different values.
  • Permanence - at any moment of our programme execution, the selected handle will always allow you to get the calculation data of the same indicator.
Another thing is if you are curious and want to rise to the level of a programming language developer. Then it makes sense to go into such nuances.
 
Yuriy Bykov #:
Another thing is if you are curious and want to rise to the level of a programming language developer. Then it makes sense to go into such nuances.
Yes, Yuri, that's exactly the point. If I try to understand something, I try to do it to the maximum. )

Regards, Vladimir.

 
MrBrooklin #:
why does the handle numbering start with 10 instead of zero?
Look what number ends the value of the ENUM_APPLIED_PRICE enumeration constants
 
Thanks, learnt some new information too.
 
MrBrooklin #:
Yes, Yuri, that's exactly the point. If I try to understand something, I try to do it to the best of my ability. )

Vladimir, just in case I ask: do you understand the difference between the terms "MQL5 programming language developer" and "developer using the MQL5 programming language"? I was talking about the former, and you probably meant the latter. But I could be wrong, of course.

 
Yuriy Bykov #:

Vladimir, just in case I ask: do you understand the difference between the terms "MQL5 programming language developer" and "developer using the MQL5 programming language"? I was talking about the former, and you probably meant the latter. But I could be wrong, of course.

Yuri, yes, the difference is absolutely clear to me. )

Regards, Vladimir.