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

 
Roman Sharanov:

below in the class file

Does this method return an error? If yes, define it in the private section. You can do it in its entirety:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class newC
  {
private:
   int      m_var;
   double   varSqrt(void)           const { return ::MathSqrt(this.m_var); }
public:
                     newC(int var);
                    ~newC();
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
newC::newC(int var)
  {
      this.m_var = var;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
newC::~newC()
  {
  }
//+------------------------------------------------------------------+

Or you can take it out:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class newC
  {
private:
   int      m_var;
   double   varSqrt(void) const;
public:
                     newC(int var);
                    ~newC();
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
newC::newC(int var)
  {
      this.m_var = var;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
newC::~newC()
  {
  }
//+------------------------------------------------------------------+
double newC::varSqrt(void) const
  {
   return ::MathSqrt(this.m_var);
  }
//+------------------------------------------------------------------+
 
neverness:

Well, if it is nonsense, it's experience-tested.

Not just "theoretical nonsense" !!!

Exactly.

I use all types of arrays in indicators safely. And as a buffer, and dynamic, and static.

But everything does not work for you and experience tells you, sorry, some nonsense.

 
Artyom Trishkin:

Does this method return an error? If yes, define it in the private section. You can define it as a whole:

And you can take it out:

Or you can simply refer to the private member of the class as this.m_var within the class.
 
neverness:

Well, if it is nonsense, it's experience-tested.

Not just "theoretical nonsense" !!!

No one is stopping you from using a dynamic array in your calculations.

But!!! The processor is busy during calculations and there will be no writing to the dynamic array.

So any data that comes into a dynamic array during calculations is automatically ignored. (Sometimes they put protection, and write them into a buffer.)

I hope this is clear?

That's why all the data on dynamic arrays are spread over static arrays, so that no data are lost while the processor works.

And that's why all calculations should be performed in static arrays !!!

This is a fierce nonsense, worthy of entering the annals of the forum.

 
Artyom Trishkin:

That's the one.

I easily use any types of arrays in indicators. And as a buffer, and dynamic, and static.

But it doesn't work for you and experience tells you, sorry, some nonsense.

Ok.

Let's carry out an experiment.

Let's take a dynamic array linked with tick data and use the processor on this array for a couple of hours.

And see what we write to that array during that time !?

Do you like this formulation of the question? (Without a buffer, of course).

 
neverness:

All right.

Let's do an experiment.

Let's take a dynamic array associated with tick data, and engage the processor on that array for a couple of hours.

And see what we write to that array during that time !?

Do you like this formulation of the question? (Without the buffer, of course).

Do it. Then the code here.

 
Artyom Trishkin:

Does this method return an error? If yes, define it in the private section. You can define it as a whole:

And you can take it out:

Yes, that's how it should be, thank you.

 
Artyom Trishkin:

Do it. Then get the code in here.

Of course.

We'll see about that later.

 

Another question.

I have a structure in a class.

How can I return it by request to external code that works with this class?

 
Roman Sharanov:

Another question.

I have a structure in a class.

How can I return it by request to external code that works with this class?

only by describing the structure itself at the global variable visibility level

then declare the structure variable in the class

and in your external code, you can declare the same variable, but keep in mind that if you declare such a variable inside OnTick(), every call to OnTick() will start a structure constructor, even if you didn't create it - in MQL, there is no difference between classes and structures, the only thing I remember, the constructor with the parameter of the structures created through new will not be passed by compiler

so... In classical OOP you don't usually get beyond the class by passing the internal elements (class fields), everything is usually realized by means of queries to the class Get() ... Set()... well, it's a matter of taste

SZ: .... use inheritance, inheritors have common classes, look at the source code of classes from MT delivery (include folder)

Reason: