The EOP for schoolchildren. - page 17

 
Artyom Trishkin:

It's exactly the same as with variables.

And the focus:

what is the point of this pointer if trade is available in the OnTrade function

#include <Trade\Trade.mqh>
CTrade trade;   // Объект № 1 в глобальной области программы

int OnInit()
{
 trade.SetExpertMagicNumber(123);
}

void OnTick()
{
 trade.Buy(0.1);
}
 
Alexey Viktorov:

What's the point of this pointer if it's available in the OnTrade function

None. But by that I showed you the difference between the way you wrote another (second) object of the same type, and the way you can access a single object by pointer.

It was a simplified example to answer your question about differences and preferences.

You know, you ask questions with overly simple examples, and when you're answered, you ask another - quite reasonable question - "why?"

Because your examples don't need to be solved with classes.

There are two options here - you either read and understand what you're being told, or... Or you solve your problems procedurally. In that case you won't have questions "for what reason".

Now imagine that your CTrade class is not in the global scope. И ?

Also imagine, that you have not only one such object (as it is in almost all examples in kodobase), but as many symbols as you manually add/remove from the program. И ?

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

In that case, is it

incorrect description?

My understanding was that if set for EA, then any orders/positions should have this magik. ((

Why is it suddenly incorrect?

One EA can have several magiks and all of them are his.

Even in one ulong-magic, you can store one common Expert ID+some mages+some different IDs, and still have plenty of room left over.

 
Artyom Trishkin:

None. But by that I showed you the difference between the way you wrote another (second) object of the same type, and the way you can access a single object by pointer.

It was a simplified example to answer your question about differences and preferences.

You know, you ask questions with overly simple examples, and when you're answered, you ask another - quite reasonable question - "why?"

Because your examples don't need to be solved with classes.

There are two options here - you either read and understand what you're being told, or... Or you solve your problems procedurally. In that case you won't have questions "for what reason".

Now imagine that your CTrade class is not in the global scope. И ?

Also imagine, that you have not one such object (as it is in almost all examples in kodobase), but as many characters you manually add/remove from the program. И ?

No, Artyom, I ask questions for understanding, not for application. And when you suggest a solution to an idiotic idea, that's when I ask "Why?". You see, if I ask back in my own way and am answered right or wrong I think, then everything I have been told about it I will no longer forget and will do so with understanding, or with understanding I will not do so. I have my own cockroaches...)) I don't know how to do something without understanding. I've never solved a math problem just from a sample solution. I don't know how. I had 5 F's and a B in maths the year I finished eighth grade. Well, they let me take the exams with the condition that if I write an essay with a C, I will be allowed to pass the exams, correct the F's and they will let me go to GPTU. The institute was much later. That's where I fell ill with programming, but it was only taught superficially. And OOP at that time, it seems to me, may have only just been conceived.

 
Alexey Viktorov:

No Artem, I ask questions for understanding, not for application. And when you offer a solution to an idiotic idea, that's when I ask "Why?". You see, if I ask back in my own way and am answered right or wrong I think, then everything I have been told about it I will no longer forget and will do so with understanding, or with understanding I will not do so. I have my own cockroaches...)) I don't know how to do something without understanding. I've never solved a math problem just from a sample solution. I don't know how. I had 5 F's and a B in maths the year I finished eighth grade. It was all right, I was allowed to take the exams with the condition that if I wrote an essay with a C, I would be allowed to pass the exams, correct the F's and I would be allowed to go to GPTU. The institute was much later. That's where I fell ill with programming, but it was only taught superficially. And OOP at that time, it seems to me, may have only just been conceived.

Then it is strange that you asked these questions in the first place.

You do understand the difference between variables declared in different scopes. You do. And you ask a question as if for the first time you hear aboutscopes of variables.

When you're shown how to use a pointer to a previously created object, you ask a strange question - "why, if the object is already visible?". So you weren't shown how to do it, but how to get a pointer in that example and refer to the object by the pointer. And it won't be two different objects in different scopes, but one.
But what if the object is not in the global scope but inside some other object? And that other object just returns a pointer to the CTrade object you need. In this case, the example would not give rise to the question "why? I think it won't. But it can be implied that you're answered on the assumption that you understand simplicity of your example and omit global object visibility "behind the brackets".

 
Artyom Trishkin:

Why would it suddenly be incorrect?

One expert can have several magicians and all of them are his.

Even in one magic you can store one common EA's ID + several magics + several different IDs and still have plenty of room left.

I understand. When making a trade request, you can specify any magician. One EA may open every new position with a new magician. I also encode the symbol, TF, etc. in my magik. All this is clear.

Only I was sure thatSetExpertMagicNumber is like a global solution. If a trade request doesn't explicitly specify a magic, then it takes the value set viaSetExpertMagicNumber. Otherwise, I personally don't see the point of it).

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

I understand. When making a trade request, you can specify any wizard. One EA may open every new position with a new magik. I also encode a symbol, TF, etc. in my magik. All this is clear.

Only I was sure thatSetExpertMagicNumber is like a global solution. If a trade request doesn't explicitly specify a magic, then it takes the value set via SetExpertMagicNumber. Otherwise, I personally don't see the point of it ))

The method sets magic number not to Expert Advisor, but to an object of a trade class. There can be several trade classes in one EA and a separate magic number can be set for each of them, which includes in its value both a common magic number for the EA and a separate magic number for each of the trade objects.

 
Artyom Trishkin:

Then it's strange that you asked these questions at all.

It's not strange at all. If I don't understand OOP at all, then I wasn't sure, or had some doubts, that I understood it correctly. Asked for clarification, got confirmation and now I'm sure (of tomorrow). Like that monologue by G. Hazanov.

- Imagine that you are standing at the window, and in the window opposite, unsuspecting is a naked woman. What do you feel?

- Confidence in the future.

- And what's your next move?

- I'm moving to another room. I have a bigger window there.

 
Alexey Viktorov:

Am I correct in assuming that with this option

without considering a compiler warning, the position may be opened with a Magic number other than 123 ?

That is, a new object will be created in the OnTick function and the magic number in it will not be equal to 123.

The position will be opened with Magic number equal to "0" - i.e. the line

void OnTick()
{
 CTrade trade;

recreates the object and CTrade magic is initialized to "0" by default (in class constructor) when creating a trade class object:

//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CTrade::CTrade(void) : m_async_mode(false),
   m_magic(0),
   m_deviation(10),
   m_type_filling(ORDER_FILLING_FOK),
   m_log_level(LOG_LEVEL_ERRORS)
 
Vladimir Karputov:

Position will be opened with Magic number equal to "0" - i.e. string

recreates the object again and CTrade magic is initialized with zero by default (in class constructor) when creating trade class object:

Yes? Doesn't it create a new, independent object?

Reason: