Questions from Beginners MQL5 MT5 MetaTrader 5 - page 618

 
Leo59:
Can you tell me why this might be the case? :
Fun_1() and Fun_2() are similar.
Similar without function type and without returns?
 
Leo59:
Can you please tell me what could be causing this? :
Fun_1() and Fun_2() are similar.

academically - the functions are not pure and change the global state.

briefly - both functions read and write a global variable or file.

 
Maxim Kuznetsov:

academically - the functions are not pure and change the global state.

in short - both functions read and write a global variable or file.

Yes, they each write a file. So?
 
Leo59:
Yes, each of them writes a file. So?

and do not work together :-)

PS. it's impossible to say more accurately about the source of the underground knocks without sources. Somewhere there is a mistake - correct it

 
To save space and improve perception - in one function. It still doesn't work.

void Fun_Select_2()                                                   // dSSd Выбор сочетаний из массивов dSe1_Bal_D и dSe1_Bal_W с Proba>67
   {
    // 1. УДАЛЯЕМ старые файлы
    // 2. ПЕРЕБИРАЕМ в поиске соответствия
    // 3. ПЕЧАТАЕМ найденное в файл

    // 1. УДАЛЯЕМ старые файлы
    if(use_Print_Rep_dSS == 1)                                        // =0 -> Условие отключено, =1 -> Печатать в log файл Промежуточные отчёты (dSS)
        {
         LogName="Rep_dSSd "+EN;                                      // (Interum Report) Название ЛОГА + Название ЭТОГО ЭКСПЕРТА, передаваемое в log файл
         // Если файл с таким именем существует, то удаляем его ... 
         ld=log_delete(LogName);                                      // ФЛАГ log файла, удаляемого в директории "logs\\" 
         if(ld==1)
              Alert ("Старый файл dSSd УДАЛЁН");
         LogName="Rep_dSSw "+EN;                                      // (Interum Report) Название ЛОГА + Название ЭТОГО ЭКСПЕРТА, передаваемое в log файл
         // Если файл с таким именем существует, то удаляем его ... 
         ld=log_delete(LogName);                                      // ФЛАГ log файла, удаляемого в директории "logs\\" 
         if(ld==1)
              Alert ("Старый файл dSSw УДАЛЁН");
        }

    // 2. ПЕРЕБИРАЕМ в поиске соответствия
    //    Находим соответствие между [1]-"Num1 А" и [4]-"Num1 B" в массивах dSe1_Bal_D и dSe1_Bal_W
    int t=0;                                                          // Техническая переменная
    int d=0;                                                          // Техническая переменная
    int w=0;                                                          // Техническая переменная
    int D=0;                                                          // Техническая переменная
    int W=0;                                                          // Техническая переменная
    int S=0;                                                          // Техническая переменная

    //    Если есть соответствие тогда записываем её в массив dSSd[][90]
    Count_dSSd=0;                                                     // "Обнуляем" Счётчик записей (строк) в массиве dSSd[][90]
    Range_dSSd_one=0;                                                 // "Обнуляем" Размер первого измерения (число строк)    с индексом_измерения=[0] массива dSSd[][90];
    Range_dSSd_two=0;                                                 // "Обнуляем" Размер второго измерения (число столбцов) с индексом_измерения=[1] массива dSSd[][90];

    for(d=0, t=0; d<Range_dSe1_Bal_D_one; d++)
        {
         for(w=0; w<Range_dSe1_Bal_W_one; w++)
             {
              if( (dSe1_Bal_W[w][1]==dSe1_Bal_D[d][1]) && (dSe1_Bal_W[w][4]==dSe1_Bal_D[d][4]) )
                  {
                   Count_dSSd++;                                      // Счётчик записей (строк) в массиве dSSd[][90]
                   ArrayResize(dSSd, Count_dSSd, 200000);             // Задайм новый размер массива с резервированием памяти на 100000 записей (строк)  
                   for(S=0,  D=0;   D<45;   D++, S++)
                        dSSd[t][S] = dSe1_Bal_D[d][D];                // Значения строки массива dSe1_Bal_D
                   for(S=45, W=0;   W<45;   W++, S++)
                        dSSd[t][S] = dSe1_Bal_W[w][W];                // Значения строки массива dSe1_Bal_W
                   t++;                                               // Увеличили индекс массива dSSd на "1"
                  }
             }
        }
    Range_dSSd_one = ArrayRange(dSSd, 0);                             // Размер первого измерения (число строк)    с индексом_измерения=[0] массива dSSd[][90];
    Range_dSSd_two = ArrayRange(dSSd, 1);                             // Размер второго измерения (число столбцов) с индексом_измерения=[1] массива dSSd[][90];

    //    Если есть соответствие тогда записываем её в массив dSSw[][90]
    Count_dSSw=0;                                                     // "Обнуляем" Счётчик записей (строк) в массиве dSSw[][90]
    Range_dSSw_one=0;                                                 // "Обнуляем" Размер первого измерения (число строк)    с индексом_измерения=[0] массива dSSw[][90];
    Range_dSSw_two=0;                                                 // "Обнуляем" Размер второго измерения (число столбцов) с индексом_измерения=[1] массива dSSw[][90];
    for(d=0, t=0; d<Range_dSe1_Bal_D_one; d++)
        {
         for(w=0; w<Range_dSe1_Bal_W_one; w++)
             {
              if( (dSe1_Bal_W[w][1]==dSe1_Bal_D[d][1]) && (dSe1_Bal_W[w][4]==dSe1_Bal_D[d][4]) )

                  {
                   Count_dSSw++;                                      // Счётчик записей (строк) в массиве dSSw[][90]
                   ArrayResize(dSSw, Count_dSSw, 200000);             // Задайм новый размер массива с резервированием памяти на 100000 записей (строк)  
                   for(S=0,  W=0;   W<45;   W++, S++)
                        dSSw[t][S] = dSe1_Bal_W[w][W];                // Значения строки массива dSe1_Bal_W
                   for(S=45, D=0;   D<45;   D++, S++)
                        dSSw[t][S] = dSe1_Bal_D[d][D];                // Значения строки массива dSe1_Bal_D
                   t++;                                               // Увеличили индекс массива dSSw на "1"
                  }
             }
        }
    Range_dSSw_one = ArrayRange(dSSw, 0);                             // Размер первого измерения (число строк)    с индексом_измерения=[0] массива dSSw[][90];
    Range_dSSw_two = ArrayRange(dSSw, 1);                             // Размер второго измерения (число столбцов) с индексом_измерения=[1] массива dSSw[][90];

    // 3. ПЕЧАТАЕМ найденное в файл
    int LH_Rep=0;                                                     // Хэндл log файла, открытого в директории "logs\\" 
    if(use_Print_Rep_dSS == 1)                                        // =0 -> Условие отключено, =1 -> Печатать в log файл Промежуточные отчёты (dSS)
        {
         if(Count_dSSd>0)
             {
              LogName="Rep_dSSd "+EN;                                 // (Interum Report) Название ЛОГА + Название ЭТОГО ЭКСПЕРТА, передаваемое в log файл
              LH_Rep=log_open(LogName);                               // Хэндл log файла, открытого в директории "logs\\" 
              Fun_Rep_mass90(LH_Rep, dSSd, Count_dSSd);               // Функция F 135 Запись Массива  mass90[][90] в Промежуточный отчёт в *.csv файл
              log_close(LH_Rep);                                      // Закрываем лог-файл этого эксперта
              Alert ("Записан ОТЧЁТ ", LogName);
             }
         if(Count_dSSw>0)
             {
              LogName="Rep_dSSw "+EN;                                 // (Interum Report) Название ЛОГА + Название ЭТОГО ЭКСПЕРТА, передаваемое в log файл
              LH_Rep=log_open(LogName);                               // Хэндл log файла, открытого в директории "logs\\" 
              Fun_Rep_mass90(LH_Rep, dSSw, Count_dSSw);               // Функция F 135 Запись Массива  mass90[][90] в Промежуточный отчёт в *.csv файл
              log_close(LH_Rep);                                      // Закрываем лог-файл этого эксперта
              Alert ("Записан ОТЧЁТ ", LogName);
             }
        }
   }
 
Leo59:
To save space and improve perception - in one function. It still doesn't work.

for future - if you may need function result (at least worked/not worked), do not make it void. At a cursory glance it is hard to determine that there is a criterion of "triggered" - it is void, no matter how you throw everything is good.

on the debugger's rights:

You have a bunch of global variables Count_XXX, Range_XXX, which you convert (plus dSSxx[] arrays), use them to decide whether to log or not and then pass them somewhere, either by reference or by value...

there's obviously something wrong with their recalculation - Count_dSS gets 0 when you call it again. Print can help to figure it out or breakpoints and watch.

 
Maxim Kuznetsov:

for future - if you may need result of function (at least it worked or not), don't make it void. At a glance, it is hard to determine what is the criterion for "triggered" - it is void, no matter how you throw it, everything is good.

on the debugger's rights:

you have a bunch of global variables Count_XXX, Range_XXX, which you convert (plus arrays dSSxx[]), based on them you decide whether to log or not and then pass somewhere either by reference or by value...

there's obviously something wrong with their recalculation - Count_dSS gets 0 when you call it again. Print can help to figure it out or breakpoints and watch.

Which callback do you mean?
A simplified version:
double   dSSd[][90];                   // Динамический Массив SelectSort соответствия пары массива dSe1_Bal_W паре массива dSe1_Bal_D
int      Count_dSSd=0;                 // Счётчик записей (строк) в массиве dSSd[][90]
int      Range_dSSd_one=0;             // = ArrayRange(dSS, 0);  Размер первого измерения (число строк)    с индексом_измерения=[0] массива dSSd[][90];
int      Range_dSSd_two=0;             // = ArrayRange(dSS, 1);  Размер второго измерения (число столбцов) с индексом_измерения=[1] массива dSSd[][90];

double   dSSw[][90];                   // Динамический Массив SelectSort соответствия пары массива dSe1_Bal_W паре массива dSe1_Bal_D
int      Count_dSSw=0;                 // Счётчик записей (строк) в массиве dSSw[][90]
int      Range_dSSw_one=0;             // = ArrayRange(dSS, 0);  Размер первого измерения (число строк)    с индексом_измерения=[0] массива dSSw[][90];
int      Range_dSSw_two=0;             // = ArrayRange(dSS, 1);  Размер второго измерения (число столбцов) с индексом_измерения=[1] массива dSSw[][90];

int init()
   {
    ArrayResize(dSSd, 200000, 200000);                                // Задаём новый размер массива с резервированием памяти на 200000 записей (строк)  
    ArrayResize(dSSw, 200000, 200000);                                // Задаём новый размер массива с резервированием памяти на 200000 записей (строк)  
    Fun_Select_2();
    return(0);
   }

void Fun_Select_2()                                                   
   {
    //    Находим соответствие между [1]-"Num1 А" и [4]-"Num1 B" в массивах dSe1_Bal_D и dSe1_Bal_W
    int t=0;                                                          // Техническая переменная
    int d=0;                                                          // Техническая переменная
    int w=0;                                                          // Техническая переменная
    int D=0;                                                          // Техническая переменная
    int W=0;                                                          // Техническая переменная
    int S=0;                                                          // Техническая переменная

    //    Если есть соответствие тогда записываем её в массив dSSd[][90]

    for(d=0, t=0; d<Range_dSe1_Bal_D_one; d++)
        {
         for(w=0; w<Range_dSe1_Bal_W_one; w++)
             {
              if( (dSe1_Bal_W[w][1]==dSe1_Bal_D[d][1]) && (dSe1_Bal_W[w][4]==dSe1_Bal_D[d][4]) )
                  {
                   Count_dSSd++;                                      // Счётчик записей (строк) в массиве dSSd[][90]
                   ArrayResize(dSSd, Count_dSSd, 200000);             // Задаём новый размер массива с резервированием памяти на 100000 записей (строк)  
                   for(S=0,  D=0;   D<45;   D++, S++)
                        dSSd[t][S] = dSe1_Bal_D[d][D];                // Значения строки массива dSe1_Bal_D
                   for(S=45, W=0;   W<45;   W++, S++)
                        dSSd[t][S] = dSe1_Bal_W[w][W];                // Значения строки массива dSe1_Bal_W
                   t++;                                               // Увеличили индекс массива dSSd на "1"
                  }
             }
        }
    Range_dSSd_one = ArrayRange(dSSd, 0);                             // Размер первого измерения (число строк)    с индексом_измерения=[0] массива dSSd[][90];
    Range_dSSd_two = ArrayRange(dSSd, 1);                             // Размер второго измерения (число столбцов) с индексом_измерения=[1] массива dSSd[][90];

    //    Если есть соответствие тогда записываем её в массив dSSw[][90]
   for(d=0, t=0; d<Range_dSe1_Bal_D_one; d++)
        {
         for(w=0; w<Range_dSe1_Bal_W_one; w++)
             {
              if( (dSe1_Bal_W[w][1]==dSe1_Bal_D[d][1]) && (dSe1_Bal_W[w][4]==dSe1_Bal_D[d][4]) )
                  {
                   Count_dSSw++;                                      // Счётчик записей (строк) в массиве dSSw[][90]
                   ArrayResize(dSSw, Count_dSSw, 200000);             // Задаём новый размер массива с резервированием памяти на 100000 записей (строк)  
                   for(S=0,  W=0;   W<45;   W++, S++)
                        dSSw[t][S] = dSe1_Bal_W[w][W];                // Значения строки массива dSe1_Bal_W
                   for(S=45, D=0;   D<45;   D++, S++)
                        dSSw[t][S] = dSe1_Bal_D[d][D];                // Значения строки массива dSe1_Bal_D
                   t++;                                               // Увеличили индекс массива dSSw на "1"
                  }
             }
        }
    Range_dSSw_one = ArrayRange(dSSw, 0);                             // Размер первого измерения (число строк)    с индексом_измерения=[0] массива dSSw[][90];
    Range_dSSw_two = ArrayRange(dSSw, 1);                             // Размер второго измерения (число столбцов) с индексом_измерения=[1] массива dSSw[][90];
   }

// Получаенный результат:

// Count_dSSd     = 280
// Range_dSSd_one = 280
// Range_dSSd_two = 90
// Массив dSSd заполнен правильными значениями

// Count_dSSw     = 280
// Range_dSSw_one = 0
// Range_dSSw_two = 90
// Массив dSSw заполнен "0"
 
// The essence of the problem is as follows:
// There are two dynamic arrays A[][2] and B[][2]
// we are looking for matches by the first dimension index "0".
// Array A Array B
// 31 25 19 66
// 44 15 62 30
// 62 47 54 71
// 31 94
// We want to get:
// Array dSSd[][4] Array dSSw[][4]
// 31 25 31 94 31 94 31 25
// 62 47 62 30 62 30 62 47
 
Leo59:
Which re-call do you mean?
A simplified version:

I am referring to a function similar to the first one (which may be different in detail). You asked the same question - why do these functions work separately, but one after the other (regardless of the order) does not. More precisely, only the first function works and records something.

well - fuck the global state, i.e. the first call of the first of these functions changed either the global variables or the contents of the arrays. Why? You should know better, why should it change when writing to a file:-) Honestly - break through

Range_dSe1_Bal_W_one

I, for example, find it hard and reluctant. Get a debugger or put printers on all suspicious places already. You understand the naming logic and have some idea how it should work (not coincident with reality :-) )

PS/ from the explanation of what's in the input and what's out, I see that instead of two arrays dSSx[][4] is enough and one dSS[][3] :-)

 
Maxim Kuznetsov:

I am referring to a function similar to the first one (which may be different in detail). You asked the same question - why do these functions work individually, but one after the other (regardless of the order) does not. More precisely, only the first function works and records something.

So - the global state is fucked, i.e. the first call of the first of these functions changed either global variables or contents of arrays. Maybe you know better why they should change it when writing to the file:-). Honestly - break through

I, for example, find it hard and reluctant. Get a debugger or put printers on all suspicious places already. You understand the naming logic and have some idea how it should work (not coinciding with reality :-) )

PS/ from the explanation of what's in the input and what's out, I see that instead of two arrays dSSx[][4] is enough and one dSS[][3] :-)

Maxim, thank you for not being indifferent. The problem is solved. It turned out to be a matter of insufficient memory.
Reason: