Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1186

 
Vladimir Karputov :

Where is the question? What exactly are the errors? Sorry, all the telepaths are on holiday.

That's the question. I also don't understand what the mistake was. Do you think I would have put it in here if I knew what the error was? I don't even get the error. Just this message and nothing else.

 
jaffer wilson:

That is the question. I also don't understand what the mistake was. Do you think I would have put it in here if I knew what the error was? I don't even get the error. Just this message and nothing else.

Click

 
Vladimir Karputov :

Where is the question? What exactly are the errors? Sorry, all the telepaths are on holiday.


OK, got it.

test on EURUSD, H1 (netting) Tradestatisticspanel (EURUSD, H1) OnInit return code is -1 cannot initialize indicator inconsistently

 

Please give me a hint!

Help says that an instance of a structure is a variable. For example, we have a structure

struct STRUCT_POSITION {
   double            volume;                 
   double            lot_coefficient;        
   bool              waiting_transaction;    
   ulong             waiting_order_ticket;   
   bool              transaction_confirmed;  
   }

Then we create an instance of the structure by declaring a variable of its type:

STRUCT_POSITION SPosition;

But I came across this in the code

STRUCT_POSITION SPosition[];

And this confused me. I haven't seen anywhere that you can declare an array of a structure type. What properties will this array have now? Can it be called a "structure instance"? Maybe you know where to read more about it?

 
odyn:

Please give me a hint!

Help says that an instance of a structure is a variable. For example, we have a structure

Then we create an instance of the structure by declaring a variable of its type:

But I came across this in the code

And this confused me. I haven't seen anywhere that it is possible to declare an array of the structure type. What properties will this array have now? Can it be called a "structure instance"? Can you tell me where to read more about this?

Forum on Trading, Automated Trading Systems and Strategy Testing

FAQ from Beginners MQL5 MT5 MetaTrader 5

Alexey Viktorov, 2020.02.23 08:29

Declaring struct STRUCT_POSITION {\...\}, this is the creation of a custom data type. And STRUCT_POSITION SPosition[]; is the declaration of a variable of the user type. Square brackets [] indicate that the variable is an array. You can declare several variables of the user type just like any other type.

double a, b[];

STRUCT_POSITION Pos, SPosition[];// при условии, что структура уже создана.
In this entry type, variable, array

Oh... I didn't notice right away that it was you who had this exact answer.

To elaborate: An array is just a set of indexed variables. Primitively, we have two variables p1 and p2 or we have array p[2], in which case it doesn't matter if we store the value in variable p1 or in a cell of array p[0], or in variable p2 or in array p[1].

When you need 2-3, or maximum 5 variables, you can do with variables, but if you need 100 or even an unknown number of variables... This is where the beauty of arrays comes in.

 
Alexey Viktorov:

Oh... I didn't immediately notice that you were the one with the answer.

In more detail: An array is just a set of indexed variables. Primitively, we have two variables p1 and p2, or we have array p[2], in which case it doesn't matter whether the value is stored in variable p1 or in a cell of array p[0], or in variable p2 or in array p[1].

If you need 2-3 variables, or at most 5, you can do with variables, but if you have 100 or even an unknown number of required variables... This is where the beauty of arrays comes in.

Alexey, do I understand correctly that an array, unlike a variable, will contain not fields of the structure, but instances of the structure, in number from zero to several ?

P.S. : the code was notSTRUCT_POSITION Pos,SPosition[]

butSTRUCT_POSITION SPosition[];

no variable.

 
odyn:

Alexey, do I understand correctly that an array, unlike a variable, will contain not fields of the structure, but instances of the structure, in number from zero to several ?

One bus (variable with structure type bus) has three fields:
1. Driver
2. Conductor
3. Passengers[].
A fleet of buses (an array of bus structures) has 120 buses, each with the same fields:
1. Driver
2. Conductor
3. Passengers[].
But each bus has these fields different from other buses.
Bottom line: a fleet of buses is an array of bus type strings.
 
Artyom Trishkin:
One bus (variable with structure type bus) has three fields:
1. Driver
2. Conductor
3. Passengers[].
A fleet of buses (an array of bus structures) has 120 buses, each with the same fields:
1. Driver
2. Conductor
3. Passengers[].
But each bus has these fields different from other buses.
Bottom line: a fleet of buses is an array of bus type strings.

Thank you, that's very clear. :) So it's an array of struts. I see.

 
odyn:

Thank you, that's very clear. :) It's a MASSIVE STRUCTURE. I see.

It was very well explained by Artem while I was absent. I will only add to your understanding: You get an array of structures containing an array of passengers.

Each cell of the array has one driver, one conductor and many passengers (array).

 
Artyom Trishkin:

Here

You are creating a base class object. Accordingly - you have a base class everywhere.

but is it possible to declare a class as a base class and then, depending on the conditions, override it as one of the inherited classes?

The task is to leave the class name the same in the code.

Also, please advise which directive to use to define the tester.

#ifdef MQL_TESTER || MQL_VISUAL_MODE

Is it possible to do it this way?

Reason: