Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1099

 
Igor Makanu:

memory allocation will be in example 1 and in example 2

Example 2 is both declaration and initialization, example 1 only declaration

Already more clear could have written about it in the help. I declared it right away because I have static calculations in classes and I don't need to create object via new operator.

Tell me, I want to do such a thing, it means I want to declare a class, then declare an array and store in the array a pointer to the class, is it possible to do or not?

 
Seric29:

Tell me I want to do such a thing, so I want to declare a class then declare an array and store in the array a pointer to the class, is it possible to do or not?

again and again.... A class is first and foremost a data type, like int, double...

you want an array of this data type? - declare an array, if the array is dynamic, then resize it, then initialize EVERY ELEMENT with the necessary data - you need pointers, then initialize them with pointers to a class, you need instances of a class, then every element of the array will not be a pointer but an object itself

that's the essence of OOP, any class is first of all a user data type.... i don't know how much to say about it, but the methodology is the same as with a normal data type, and what you will write inside the class is a personal matter, but the initialization of a new instance will always start with a constructor, and what constructor there is - by default, with parameters or without parameters it gives you a choice how to initialize the object...... ugh, but still read books, there is no way to do it with questions here

 
Igor Makanu:

Usually they determine the outermost upper/lower orders by their open prices, then add some value and get a new price at which they either monitor when the price breaks this level-condition and place a new order or immediately place a grid of pending orders aiming at the maximum number of orders and then trace this grid.

I thank you for your interest, but I meant the dotted grid on the chart.


Can you please advise how horizontal levels are calculated for a grid in mt4 and in mt5? They shift when I scroll the chart without a fixed scale and they shift inmt4 and mt5 a bit differently. Maybe someone knows how it is calculated, so you don't have to guess with indentations, bindings and so on.

 
Andrey Sokolov:

Thank you for not passing us by, but I'm not talking about that, I'm talking about the dotted grid on the chart.


Can you please tell me how horizontal levels are calculated for the grid in mt4 and in mt5? If the scale is not fixed, they shift when I scroll the chart, and they shift inmt4 and in mt5 a bit differently. Maybe someone knows how it's calculated so I don't have to guess with indents, bindings and stuff.

It just divides the window into equal parts, depends on the screen resolution.

I am dividing vertically into 15 parts in both MT4 and MT5

 
Igor Makanu:

again and again.... A class is first and foremost a data type, like int, double...

you want an array of data of that type? - declare an array, if the array is dynamic, then resize it, then initialize EVERY ELEMENT with the necessary data - you need pointers, then initialize them with pointers to the class, you need class instances, then each element of the array will not be a pointer, but the object itself

that's the essence of OOP, any class is first of all a user data type.... i don't know how much to say about it, but the methodology is the same as with a regular data type, and what you will write inside the class is a personal matter, but the initialization of a new instance will always start with a constructor, and what constructor - by default, with or without parameters - you can choose how to initialize an object...... ugh, but still read books, there is no way to do it in this way

Yes, I realized that this is not possible because when you create an array, the program needs to specify the type, and because I want to save a pointer of different classes in one array, it will not work because the array can not be different type or miscellaneous in mql, in s++ did it, but not with such complex objects. So my idea won't work here.

 
Seric29:

Yes, I realized that this is not possible because when you create an array, the program requires you to specify the type, and because I want to save a pointer of different classes in one array, it will not work because the array can not be of different types or varieties in mql, in C++ did it, but not with such complex objects. So my idea won't work here.

Everything is done. You inherit your objects from the base class and create an array with the type of the base class. And all inherited objects can be in the array.
 
Artyom Trishkin:
Everything is done. You inherit your objects from the base class and create an array with the type of the base class. And all inherited objects can be in the array.

And show the simplest and most primitive example, where there are 2 classes then inheritance and how to put references to each class in an array of 2 elements(0 first class 1 2nd)?

 
Andrey Sokolov:

Makar, why are you writing something that is clearly untrue? When scrolling the chart you can change the offset of the horizontal grid lines, and they shiftslightly differently inmt4 and in mt5.

They don't!

They only shift when there is an indicator window, in all other cases they do not.

 
Seric29:

And show the simplest and most primitive example where there are 2 classes further inheritance and how to put references to each class in an array of 2 elements(0 first class 1 2nd)?

class CBase{
protected:
   int v;
   public:
                  CBase(): v(0)  {            }
           int    getV()         { return(v); }
   virtual int    calc() = 0;
};

class A:public CBase
{
   public:
   virtual int calc() {return(--v);} //декремент 
};

class B:public CBase
{
   public:
   virtual int calc() {return(++v);} //инкремент
};

//+------------------------------------------------------------------+
void OnStart()
{
// 2 указателя которые инициализируем экземплярами обьектов  A и B
   CBase *arr_base[2];
   arr_base[0] = new A;
   arr_base[1] = new B;
// вызовем 10 раз метод calc() для каждого обьекта   
   for(int j=ArraySize(arr_base)-1; j>=0; j--)
   {
      for(int i=0; i<10; i++)
         {
            arr_base[j].calc();
         }
   }
   
   Print("A.v = ",arr_base[0].getV());
   Print("B.v = ",arr_base[1].getV());
//удалим обьекты   
   for(int j=ArraySize(arr_base)-1; j>=0; j--)
   {
      delete arr_base[j];
   }   
}
//+------------------------------------------------------------------+

2020.03.22 21:21:38.544 tst (EURUSD,H1) A.v = -10

2020.03.22 21:21:38.544 tst (EURUSD,H1) B.v = 10

 
Igor Makanu:

2020.03.22 21:21:38.544 tst (EURUSD,H1) A.v = -10

2020.03.22 21:21:38.544 tst (EURUSD,H1) B.v = 10

Thank you. And the functions should be virtual simple can't, I will already experiment myself.

Reason: