Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1479

 
Alexey Viktorov #:

Outputting variables to the global scope is not passing arguments to a function...

Put & before variable names at the input to the function and all problems will be solved.

Hi Alexey, so that's the problem!!! Thank you very much, dear! All my head was broken, I thought there was something else missing! It turned out that brains are not enough!!!! ))

Regards, Vladimir.

 
Alexey Viktorov #:
Put & in front of variable names on function input and all problems will be solved

I found and watched the video about functions with references. From this video lesson I realised that I need not just an MQL5 lesson for beginners, but an MQL5 lesson for especially gifted beginners with stupidity. In short, I didn't understand anything. In general, you need to digest all the information you have received and re-watch this video five or even six times. But there will be something to do in my spare time! ))

Regards, Vladimir.

 
MrBrooklin #:

I found and watched a video about functions with links. From this video lesson I realised that I need not just an MQL5 lesson for beginners, but an MQL5 lesson for beginners who are especially gifted with stupidity. In short, I didn't understand anything. In general, you need to digest all the information you have received and re-watch this video five or even six times. But there will be something to do in my spare time! ))

Regards, Vladimir.

Do not waste time, even if you have nowhere to spend it. The name of the "teacher" speaks for itself, a dilettante is a dilettante.

This video is only useful to you for 3 minutes. And the rest is only distracting and you lose useful information.

It is better to read the documentation carefully, experiment with examples and you will understand everything.

Документация по MQL5: Основы языка / Функции / Передача параметров
Документация по MQL5: Основы языка / Функции / Передача параметров
  • www.mql5.com
Передача параметров - Функции - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Alexey Viktorov #:

Don't waste time, even if there's nowhere to waste it. The name of the "teacher" alone speaks for itself, an amateur is an amateur.

There's only 3 minutes of useful information in this video. The rest is just a distraction and you lose useful information.

It is better to read the documentation carefully, experiment with examples and you will understand everything.

Thank you, Alexey, I thought that the video lesson would be more informative and useful for me, but it turned out to be exactly the opposite. As for the MQL5 Reference Manual, the Parameter Transmission section, I read it in the same way, but it turned out like the famous saying: "I look in the book, I see the figure!". I didn't understand anything. In short, of course, I will reread and experiment a few more times, I don't have much choice. ))

Regards, Vladimir.

 

After watching the video tutorial and reading about passing arguments by reference in the MQL5 Reference Manual, it seems to be more or less clear. However, having analysed the code presented in the Reference Manual, one fragment still caused perplexity, although, in my opinion, it has nothing to do with passing arguments by reference:

//+------------------------------------------------------------------+
//| передача параметров по ссылке                                    |
//+------------------------------------------------------------------+
double SecondMethod(int &i,int &j)
  {
   double res;
//---
   i*=2;
   j/=2;
   res=i+j;
//---
   return(res);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---.
   int a=14,b=8;
   Print("a и b перед вызовом:",a," ",b);
   double d= SecondMethod(a,b);
   Print("a и b после вызова:",a," ",b);
  }
//+------------------------------------------------------------------+
//--- результат выполнения скрипта
//  a и b перед вызовом: 14 8
//  a и b после вызова: 28 4

In this regard, I have a question for MQL5 programming experts - why the hell did they "shove" the SecondMethod(a,b ) function into the d variable in OnStart( )? Is it a prerequisite for the correct operation of the script, or is there something I have misunderstood again?

Regards, Vladimir.

 

Help me, please.

There are many arrays with time, and the time of some elements in these arrays can coincide.

I need to collect them into one array without repeating time values.

I did it this way:

struct str1
  {
   int               time[];// в массиве порядка 10 тыс элементов
  };

struct str2
  {
   str1              arr[];// в массиве порядка 1 тыс элементов
  };

str2 m_name[]; // в массиве порядка 100 элементов

int ArrFull[]; // массив в который нужно собрать отсортированное время без повторений
//+------------------------------------------------------------------+
void OnStart()
  {
// считаем что m_name[] ранее уже заполнили


   int tempArr[];// объявляю дополнительный массив

   int size1 = ArraySize(m_name);
   for(int i = 0; i < size1; i++)
     {
      int size2 = ArraySize(m_name[i].arr);
      for(int j = 0; j < size2; j++)
        {
         // копирую в дополнительный массив все массивы времени из структур
         ArrayInsert(tempArr, m_name[i].arr[j].time, ArraySize(tempArr));
        }
     }
// сортирую дополнительный массив
   ArraySort(tempArr);

   int size = ArraySize(tempArr);
   ArrayResize(ArrFull, size);
   ArrFull[0] = tempArr[0];
   int j = 1;

// копирую не повторяющиеся элементы из дополнительного массива в массив с которым в дальнейшем буду работать
   for(int i = 1; i < size; i++)
      if(ArrFull[j - 1] != tempArr[i])
        {
         ArrFull[j] = tempArr[i];
         j++;
        }

   size = ArrayResize(ArrFull, j);

// дальше продолжение. много много букв
  }
//+------------------------------------------------------------------+


But it turned out to be a very slow code. It needs to be faster. How to ????

 
MrBrooklin arguments by reference in the MQL5 Reference Manual, it seems to be more or less clear. However, having analysed the code presented in the Reference Manual, one fragment still caused some confusion, although, in my opinion, it has nothing to do with passing arguments by reference:

In this regard, I have a question for MQL5 programming experts - why the hell did they "shove" the SecondMethod(a,b ) function into the d variable in OnStart( )? Is it a prerequisite for the correct operation of the script and I have misunderstood something again?

Regards, Vladimir.

The d variable is assigned the result of the function execution
 
Artyom Trishkin #:
The variable d is assigned the result of the function execution

Thank you, Artyom, for your response! Isit impossible to use just the function SecondMethod(a,b) without assignment?

Regards, Vladimir.

 
MrBrooklin #:

Thank you, Artyom, for your response! Isit impossible to use just the function SecondMethod(a,b) without assignment?

Regards, Vladimir.

Yes, you can. Then two values will be received - only in the variables passed by reference. That is, the function returns three values
 
Artyom Trishkin #:
Can. Then two values will be received - only in the variables passed by reference. That is, the function returns three values

For the sake of interest, I removed the d variable. I left only the function. The result of printing has not changed. To be honest, I don't understand about the three values at all.

Regards, Vladimir.

Reason: