Errors, bugs, questions - page 1440

 

MT 4. MathRand() random number generator inside OnTick(). When testing the owl, different results are obtained when it is run again on the same settings. This is natural if the generated number affects the algorithm.

When optimizing, I get for some reason identical results on a second run with the same settings. So MathRand() doesn't work in optimization mode?

 
Сергей Таболин:

Second (I'm afraid of making a mistake here, I hopeAlexander Puzanov will correct me if anything), if the programmer for some reason decides to add an item with index 20 to a dynamic array, nothing bad will happen. The array will take this dimension and write a value there and initialize the "missing" indexes with zero values.

Exactly. Why "zero"? Maybe it should be EMPTY_VALUE ? Or WRONG_VALUE ?

The problem of such implicit assignments is exactly their implicit nature - the compiler introduces some code, which one programmer thinks one way, while another might think differently.

Plus it's ineffective - it's not always necessary to initialize a variable immediately, and initializing a large array, in a loop, can significantly reduce the speed.

And third, no one prevents the programmer from controlling the dimensionality and the index used! The only difference is that now he is forced to do it! )))

If the compiler keeps track of an array's dimension itself, no class will be able to clean up this code. The efficiency may very well drop.

At the same time, if the compiler does not take care of this task, the programmer can write a class to do this and then use an array which can be expanded and initialized with zeroes where necessary.

In the second case, the flexibility is higher.

So, what you propose is also a good solution for many cases. But it may decrease efficiency, which is not good.

 
Сергей Таболин:

This is, in principle, a simple example of how a dynamic array should normally be filled. I haven't written in C for a long time, I don't remember, but that's how arrays are filled in php! Everything is logical and understandable. If I add an element to an array (arr[] = x), the array is automatically expanded, and the element is added to the end of the array. And we don't have to stretch it out by ourselves, and we don't have to specify the element's index by ourselves. But here we have to make absolutely unnecessary movements:

the difference is obvious...

In my opinion, it's strange, to say the least ))))

Programming languages are divided into strictly-typed and not. Your PHP, R and other functional languages belong to the non-strictly-typed ones. In strictly-typed languages like MQL or C# and Java this kind of ambiguous data manipulation is not allowed. And this is done specifically for the safety of the programmer himself. Strict typing implies that each of your procedures is extremely specific: "to take an element at index 0 in array array" is a specific and clear procedure, but you propose to replace it with "take something from array array and add it to whatever the compiler decides to return first". - You agree that you won't get far on this.

On the other hand, of course, we want simple high-level constructs without tiresome array sizing and constant user rearranging. That's exactly what the standard library is for. Instead of using basic arrays, switch to the classes of the Array group. This is how, for example, adding from zero to 16 into the CArrayInt array looks like:

#include <Arrays\ArrayInt.mqh>

void OnStart()
{
   CArrayInt array;
   for(int i = 0; i < 16; i++)
      array.Add(i);   
}

As you can see, there is nothing too natural. And there's no need to rack your brains over the current array size and other rearrangements. Everything is done for you, within strict typing, and you are invited to concentrate directly on the user task. This is the power and the point of OOP.

 

Full recording not available. Compilation error

template<typename T>
class A { protected:
        A( T t ) : t( t ) {}
        T t;
};
class B : A<int> {
        B() : A<int>( 1 ) {} //'<' - member(s) initialization expected
};
 

I can't find where I'm wrong.

The task is to find the maximum and minimum value on an interval

void OnStart()

  {
int            Kol_Kan=10;       //Количество элементов для копирования
double         HI[];             //массив для хранения максимумов на интервале
double         LO[];             //массив для хранения минимумов на интервале

CopyHigh(_Symbol,0,2,Kol_Kan,HI);//копируем значения максимумов
CopyLow(_Symbol,0,2,Kol_Kan,LO); //копируем значения минимумов

ArrayResize(HI,Kol_Kan);         //устанавливаем размер массива
ArrayResize(LO,Kol_Kan);

int in_max=0;                    //индекс максимального значения в массиве
int in_min=0;

in_max=ArrayMaximum(HI,WHOLE_ARRAY,0); //Находим индексы максимума и мин в массивах
in_min=ArrayMinimum(LO,WHOLE_ARRAY,0);

double hi_max;                   // максимальное значение цены 
double lo_min;                   // минимальное значение цены

hi_max=HI[in_max];               //Переносим значения максимумов и мин в переменные
lo_min=LO[in_min];
Alert(hi_max,"___",lo_min);   

  } 
 

Wrong order of arguments in ArrayMaximum(), ArrayMinimum().

 
PabloEs:

I can't find where I'm wrong.

The task is to find the maximum and minimum value on an interval

Functions

CopyHigh(_Symbol,0,2,Kol_Kan,HI);//copy values of maxima

CopyLow(_Symbol,0,2,Kol_Kan,LO); //copy values of minima

already resize the array.

This is unnecessary

ArrayResize(HI,Kol_Kan); //set the array size

ArrayResize(LO,Kol_Kan);

 
Sergei Vladimirov:

Неправильный порядок аргументов в ArrayMaximum(), ArrayMinimum().

Exactly)) And here I was thinking...

Vladimir Pastushak:

Functions

CopyHigh(_Symbol,0,2,Kol_Kan,HI);//copy values of maxima

CopyLow(_Symbol,0,2,Kol_Kan,LO); //copy values of minima

already resize the array.

This is unnecessary

ArrayResize(HI,Kol_Kan); //set the array size

ArrayResize(LO,Kol_Kan);

I will know this, thank you.

 
PabloEs:
So what's wrong? I can't figure it out myself?
 

The author, on the other hand, has already figured it out. ))

PabloEs:

Exactly.)) And here I was thinking...

Reason: