Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1247

 
MrBrooklin:

Good evening everyone!

In my old age I'm trying to master the basics of MQL5. My curiosity is killing me - I wonder if I can't master programming if I'm about 60. Although, I have made friends with simple HTML, I even created my own web-sites in it. Simple, really, but still... If my questions will cause irritation, then tell me immediately, then I will not ask more naive questions and will not irritate people.

So, opened the first code I saw. I commented out the meaning of one line of this code using Google Translator and MQL5 Reference. What do I ask from the community? Look at the comments and if they are not true, please correct my thinking:

It's an open book to some, but to me it looks like the same Chinese characters. Please don't laugh too hard.

Why am I doing this? Thus, I'm just trying to find out for myself how hopeless I am in programming.

Regards, Vladimir.

I recommend to use the ME helper - it describes the purpose of all operators and language functions.

https://www.mql5.com/ru/docs/trading/positionselect

Документация по MQL5: Торговые функции / PositionSelect
Документация по MQL5: Торговые функции / PositionSelect
  • www.mql5.com
Выбирает открытую позицию для дальнейшей работы с ней. Возвращает true при успешном завершении функции. Возвращает false при неудачном завершении функции. Чтобы получить информацию об ошибке, необходимо вызвать функцию GetLastError(). При независимом представлении позиций (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING) по каждому символу одновременно...
 
MrBrooklin:

Good evening everyone!

In my old age I'm trying to master the basics of MQL5. My curiosity is killing me - I wonder if I can't master programming if I'm about 60. Although, I have made friends with simple HTML, I even created my own web-sites in it. Simple, really, but still... If my questions will cause irritation, then tell me immediately, then I will not ask more naive questions and will not irritate people.

So, opened the first code I saw. I commented out the meaning of one line of this code using Google Translator and MQL5 Reference. What do I ask from the community? Look at the comments and if they are not true, please correct my thinking:

It's an open book to some, but to me it looks like the same Chinese characters. Please don't laugh too hard.

Why am I doing this? Thus, I'm just trying to find out for myself how hopeless I am in programming.

Regards, Vladimir.

If you have the will, it is better for your brain than solving crosswords. Just try to understand right away that Hadge accounts are written differently than Netting accounts. This line of code

if(PositionSelect(_Symbol)) // если выбираем открытую позицию на графике текущего символа

is used for Netting, but may cause errors in Hadge accounts if more than one position is open.

 
Aleksey Vyazmikin:

I recommend using the ME helper - the purpose of all operators and language functions are described there.

https://www.mql5.com/ru/docs/trading/positionselect

Hi Alexey!

Thank you for your feedback. I am using the help in MetaEditor. At the moment the main problem is to understand the purpose of operators and functions, as well as why I need a certain operator or function in a certain place of the program code. It is kind of all described in the FAQ, but as I understand this information is not for those who starts to get into details from scratch, but for those who already has some experience in programming in other languages.

Regards, Vladimir.

 
Alexey Viktorov:

If you want to, it's better for your brain than doing crossword puzzles. Just try to understand right away that Hadge accounts are not written the same way as Netting accounts. This line of code

This line of code is used for Netting but might cause errors in Hadge accounts if more than one position is opened.

Hello Alexey!

Thank you for the tip on the Hadge and Netting accounts, as well as for the support.

I have understood that if there is no correction in comments to a code line, it's already good. It means I have understood the essence of this code line as closely as possible. I will continue studying the MQL5 programming and occasionally post my comments. Perhaps, at some point of self-study I will be able to develop a simple Expert Advisor's code on my own.

Sincerely, Vladimir.

Документация по MQL5 - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
Документация по MQL5 - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
  • www.mql5.com
MetaQuotes Language 5 (MQL5) - язык программирования технических индикаторов, торговых роботов и вспомогательных приложений для автоматизации торговли на финансовых рынках. MQL5 является современным языком высокого уровня и разработан MetaQuotes Software Corp. для собственной торгово-информационной платформы. Синтаксис языка максимально близок...
 

Hi all!

I keep learning MQL5 and here is a new line of code, which is not clear even after working with it via Help and Google Translate.

FileSeek(FileHandle,0,SEEK_SET); // перемещаем положение указателеля в файле с уникальным указателем на "0" байт в начале файла

The comment is made by me, but its meaning is not totally clear. I have hardly figured out what FileHandle is. Split it into two words File and Handle. Google translated it as a file descriptor. What is a descriptor and what does it do? It is good that the author of the article explained here https://www.mql5.com/ru/articles/496 that Handle is a unique pointer to something (a file, an indicator, etc.) in Russian.

Now it remains to understand the meaning of all code. I am asking for help from the community, I spent so much time with this code until 3 am, and my head is completely clumsy.

Regards, Vladimir.

Быстрый старт или краткий курс для начинающих
Быстрый старт или краткий курс для начинающих
  • www.mql5.com
Здравствуй дорогой читатель. В данной статье я попробую рассказать и покажу как можно просто и быстро освоить принципы построения торговых советников, работу с индикаторами и т.д. Эта статья ориентирована на новичков, в ней не будет сложных и трудных для понимания примеров. Скорей всего, она не будет интересной и познавательной для тех, кто уже...
 
MrBrooklin:

Hi all!

I keep learning MQL5 and here is a new line of code, which is not clear even after working with it via Help and Google Translate.

The comment is made by me, but its meaning is not totally clear. I have hardly figured out what FileHandle is. Split it into two words File and Handle. Google translated it as a file descriptor. What is a descriptor and what does it do? It is good that the author of the article explained here https://www.mql5.com/ru/articles/496 that Handle is a unique pointer to something (a file, an indicator, etc.) in Russian.

Now it remains to understand the meaning of all code. I am asking for help from the community, I spent so much time with this code until 3 am, and my head is completely clumsy.

Sincerely, Vladimir.

But why should you translate something in google when the documentation has everything written in Russian?

Moves the position of the file pointer by the specified number of bytes relative to the specified position.

And I would translate your comment as follows: "Moves file pointer from beginning by 0 bytes. In other words, to the beginning of the file."

Reference point for the offset. Can take one of the values of ENUM_FILE_POSITION

Identifier

Description

SEEK_SET

Start of file

SEEK_CUR

Current file position of the file pointer

SEEK_END

End of file

Документация по MQL5: Файловые операции / FileSeek
Документация по MQL5: Файловые операции / FileSeek
  • www.mql5.com
//|                                                Demo_FileSeek.mq5 | //|                        Copyright 2013, MetaQuotes Software Corp. | //|                                              https://www.mql5.com | //| Script program start function                                    |...
 
Alexey Viktorov:

And why translate something with google, when it's written in Russian in the documentation?

And I would translate your comment as, "Moves the file pointer from the beginning to 0 bytes. In other words, to the beginning of the file."

Identifier

Description

SEEK_SET

Start of file

SEEK_CUR

Current file position of the file pointer

SEEK_END

End of file

Hello Alexey!

I googled the meaning of the word combination FileHandle. I wanted to understand what it was and where it came from. The Help did not help me, so I had to Google. When I figured it out, it turned out that the author of the code himself had created a variable for storing the file with a unique pointer. In terms of FileSeek and SEEK_SET the help helped me, but the meaning of the string was not clear. Now, with the help of your tip, it became clear what it is for in a file with a unique pointer.

Thank you very much for your help!

Sincerely, Vladimir.

Документация по MQL5: Константы, перечисления и структуры / Константы ввода/вывода / Позиционирование внутри файла
Документация по MQL5: Константы, перечисления и структуры / Константы ввода/вывода / Позиционирование внутри файла
  • www.mql5.com
Большая часть файловых функций связана с операциями чтения/записи информации. При этом с помощью функции FileSeek() можно указывать положение файлового указателя на позицию внутри файла, с которой будет...
 
MrBrooklin:

Hello Alexey!

I googled the meaning of the phrase FileHandle. I wanted to understand what it is and where it came from. The Help was not helpful, so I had to go to Google. The help text for FileSeek and SEEK_SET was very helpful, but the meaning of the string was not clear. Now, with the help of your tip it became clear what it is for in the file with unique pointer.

Thank you very much for your help!

Regards, Vladimir.

The pointer is not unique, it's just the start position of a write or read. Sort of like how we write a statement. The header starts on the second half of the page, the rest of the text on the left edge of the page. Or we start a new paragraph a little back from the edge of the line. This is the beginning of the line and this is the pointer. We can move the beginning of a line to any place in existing text and write or read from that place.

The file handle is unique. It can also be called an identifier. In fact, it is a usual variable. You can call it abrakadabra and assign it a file handle.

 
Sergey:

Good afternoon !

I'm trying to figure out the indicator code. Stuck on one line.

What does the last line mean and how can it be rewritten in a simpler (clearer) way?

It is written much simpler than any other construction. It's called: ternary operator

cancl[i] = (acD==1 && aoD==1) ? 0 : (acD==2 && aoD==2) ? 1 : (acD==1 && aoD==2)? 2 : 3;
cancl[i] = if(acD==1 && aoD==1) { 0 } else { if(acD==2 && aoD==2) { 1 else { (acD==1 && aoD==2)? 2 : 3;
I've shown the code conventionally, so hopefully you'll get the hang of it
Документация по MQL5: Основы языка / Операторы / Условный оператор ?:
Документация по MQL5: Основы языка / Операторы / Условный оператор ?:
  • www.mql5.com
В качестве первого операнда – "выражение1" – может быть использовано любое выражение, результатом которого является значение типа bool. Если результат равен , то выполняется третий операнд – "выражениеЗ". Второй и третий операнды, то есть "выражение2" и "выражениеЗ", должны возвращать значения одного типа и не должны иметь тип void. Результатом...
 
Sergey:

Good afternoon !

I am parsing the code of the indicator. I am stuck on one line.

What does the last line mean and how can it be rewritten in a simpler (clearer) way ?

// cancl[i] = (acD==1 && aoD==1) ? 0 : (acD==2 && aoD==2) ? 1 : (acD==1 && aoD==2)? 2 : 3;

if      (acD==1 && aoD==1)   { cancl[i]=0; }
else if (acD==2 && aoD==2)   { cancl[i]=1; }
else if (acD==1 && aoD==2)   { cancl[i]=2; }
else                         { cancl[i]=3; }

but it's not simpler or clearer in my opinion. It's almost in the style of MT :-) To be in style there should be more strings and they should go in a "staircase" style :-)