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

 
lil_lil:

MTF indicator, I put H1 in external settings, I attach it to M15 chart. The signal flashes on bar 4. When H1 bar is closed, the signal does not blink, on M15 the signal stops blinking on bar 4. If I put it on М1, respectively, it stops blinking on bar 60. so i+N should be calculated so that N varies depending on the selected period in the settings and on the chart of the period, in which indicator is attached.

Do you have the whole code?

 

Good afternoon. I can't figure it out, OOP apologists, please help.

So, there is a class, for example CCandle. In this class, there will be the same parameters for all objects of this class. These parameters can also be initialized in OnInit() and they will be the same for all objects of this class. So, how can I do it correctly, so they won't be initialized every time when creating a new object. Suppose they all in CCandle::Init() function. I can't figure it out.

 
Juer:

Good afternoon. I can't figure it out, OOP apologists, please help.

There is a class, for example CCandle. In this class, there will be the same parameters for all objects of this class. These parameters can also be initialized in OnInit(), and they will be the same for all objects of this class. So, how can I do it correctly, so they won't be initialized every time when creating a new object. Suppose they all in CCandle::Init() function. I can't figure it out.

This is done in the initialization list, which is located in the class constructor:

class CCandle
{
   int      m_nA;
   double   m_fB;
   datetime m_dtC;


   void CCandle::CCandle(void);
};

CCandle::CCandle(void)
            : m_nA(0)
            , m_fB(0.0)
            , m_dtC(0)
{
}
 
Juer:

Good afternoon. I can't figure it out, OOP apologists, please help.

So, there is a class, for example CCandle. In this class, the parameters will be the same for all objects of this class. These parameters can also be initialized in OnInit() and they will be the same for all objects of this class. So, how can I do it correctly, so they won't be initialized every time when creating a new object. Suppose they all in CCandle::Init() function. I can't figure it out.

Make a parametric constructor in a class, and pass to it the necessary parameters to initialize the object
 
I didn't understand anything. Initialising for an object is not a problem. How do I initialise once for all objects of a given class? That is, a new object is created and the parameters are already initialized with values, without having to initialize them each time for each new object.
 
Colleagues, please advise whether it is correct to usereturn operator from the loop body? For example, we have a function with a loop. At some moment we need to return some value and thus exit the function. The correct way is to use break and then return(value). But can we use return(value) right away?
 
Juer:
I didn't understand anything. Initialising for an object is not a problem. How do I initialise once for all objects of a given class? That is, a new object is created and the parameters are already initialized with values, without having to initialize them each time for each new object.
The parameters can be initialised from the one that exists.
 
lsv107:
Colleagues, please advise whether it is correct to usereturn operator from the loop body? For example, we have a function with a loop. At some moment we need to return some value and thus exit the function. The correct way is to use break and then return(value). But can we just return(value) at once?
Nothing prevents you from exiting the loop.
 
Artyom Trishkin:
Parameters can be initialised from something that exists.

It's kind of a simple question, isn't it? The point is to initialise the same thing.

 
Artyom Trishkin:
There is nothing stopping you from exiting the loop.

I was just afraid that the loop would remain active inside the function and the return operator would only transfer control from the active loop to the call point, there would be a risk of stack overflow if the function was called again (recursion). This was exactly the case in Pascal and, by the rules of structural programming in general, loops should be terminated one after another and then the function is exited. If return, along with a function, terminates the loop, great, but I should have clarified it, as I'm back to programming after a long break.

Reason: