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

 
Roman Sharanov:

I created a variable in private

I try to work with it in a class method

it says the variable is not declared

???

Where's the code?

 
Artyom Trishkin:

Where is the code?

the function must not be accessible from external code

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

I created a variable in private

I try to work with it in a class method

it says the variable is not declared

???

Artyom Trishkin:

But it's not right.

Who prevents to use a dynamic array in calculations? The size of a dynamic array (if it's NOT an indicator buffer, which is monitored by a subsystem) you have to watch for yourself, and if necessary, change its size. A static array has a fixed size all the time - it all depends on the task at hand.

What is this unwarranted nonsense? Indicators, in their vast majority, are only calculating and displaying the required and sufficient amount of calculated data. All the time, on every tick.

What are you talking about? Ignorance? Then it's better to remain silent. Then people will say they read it on the official MK forum. Are you deliberately creating a lie?

Artem! Don't bore me.

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

But!!! During calculations the processor is busy, and there will be no writing into the dynamic array.

So any data that arrives in 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 the calculations should be performed in static arrays !

Of course, the size of static arrays should be set "to spare". This is obvious.

But you can calculate in them for as long as you like. Nothing will get lost in the process.

I hope this is clear to you?

 
Roman Sharanov:

the function needs to be inaccessible from external code

Where is the public method to access var ?

It goes something like this:

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

You use the Var() method to get var;

 
neverness:

Artem! Don't bore me.

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 arrives in 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 the calculations should be performed in static arrays !

Of course, the size of static arrays should be set "to spare". This is obvious.

But you can calculate in them for as long as you like. Nothing will get lost in the process.

I hope it is clear.

Bullshit.

 
Artyom Trishkin:

Where is the public method of accessing var ?

It goes like this:

Use the Var() method to get var;

so it will then be accessible from external code? i need these variables only brewed inside the class

 
Roman Sharanov:

so it will then be accessible from external code? I only need these variables to be brewed inside the class

Where is this method defined?

//+------------------------------------------------------------------+
double varSqrt(){
   return MathSqrt(var);
}
//+------------------------------------------------------------------+
 
Artyom Trishkin:

Where is this method defined?

below in the class file

 

Если говорить об индикаторах, то индикаторы (вообще говоря!) следует вычислять. Но в МТ4/МТ5 мы этого не наблюдаем!

What unfounded nonsense is this? Indicators, in their vast majority, do nothing but calculate and display the necessary and sufficient amount of calculated data. All the time, on every tick.

What's with all the nonsense? Out of ignorance? Then it's better to remain silent. Then people will say they read it on the official MK forum. Are you deliberately creating a lie?

Artem!

Are there static arrays in MT4/MT5 indicators ?????????????????????

In which one, I`d like to know?

What kind of defect? - I told you right away - if there is one, tell me where?

All the indicators in MT4/MT5 that I know are dynamic.

Yes, tracking all the time. Yes, on every tick.

But these are dynamic arrays, not static.

And there's no "disruption" here.

 
Artyom Trishkin:

Bullshit.

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

Not just "theoretical nonsense" !!!

- If the calculations are quite long, the ticks are not written to the data array involved.

THIS IS A FACT !!!