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

 
Can you tell me if there is a way to change the opening times of bars h4 and d1? Roughly speaking to simulate a change of time zone. Maybe a script that builds offline charts based on h1 timeframe or something like that.
 
Artyom Trishkin:

Execution cannot be pardoned.

What is the error?

Here.

As you can see, you cannot pass a locally declared structure to a function.

 
vladnev:
Can you please tell me if there is a way to change opening times of bars h4 and d1? Roughly speaking imitate a change of timezone. Maybe a script that builds offline charts based on h1 timeframe or something like that.
iOpen(Symbol,нужный таймфрейм,номер бара(счёт идёт справа налево))

We need to work with this

 
Seric29:

Here.

As you can see, you cannot pass a locally declared structure to a function.

You are confusing structure definition with declaration of a variable with the type of this structure.
 
Artyom Trishkin:

Can you check it yourself? Difficult? And why write too much?

I haven't checked. What's stopping you?

Artyom, this option really won't work. The structure has to be defined at the global variable level. And a variable of structure type is anywhere. Then it will be possible to pass it by reference. Because the type in incoming function parameters will not be defined.

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
   struct MyPoint
     {
      int         x[5];
      int         y;
     }gw777; // Переменная глобального уровня, просто лишняя.
int OnInit()
  {
   MyPoint qw1; // Локальная переменная
   EqualPointsP(qw1);// передал структуру в функцию EqualPointsP
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool EqualPointsP(MyPoint &qw)
  {
   Print("EqualPointsP ");
   return true;
  }
 
Artyom Trishkin:
You confuse definition of a structure with declaration of a variable with the type of this structure.

Meaning. You mean that the structure must be declared globally, i.e. outside the code, and the structure by its definition cannot be described inside the code, i.e. locally; only variables can be created this way, or am I misunderstanding something? Please explain.

 
Alexey Viktorov:

Artyom, this variant really won't work. The structure should be defined at the level of global variables. And a variable of structure type is anywhere. Then it will be possible to transfer it by reference. Because the type in incoming parameters of function will not be defined.

So it's global after all.

 
Seric29:

So it's global after all.

NO. A structure is a user-defined type. So this type must be available everywhere. And a VARIABLE of a custom type can be declared wherever the left pinky of the right foot wants and pass this variable wherever the beloved dog wants, but only by reference.

 
Alexey Viktorov:

This way the structure will not work, Artyom. The structure must be defined at the level of global variables. And the variable of structure type is anywhere. Then it will be possible to transfer it by reference. Because the type in incoming function parameters will not be defined.

 

In general, since Artyom does not answer anything, and the man above gave the answer that functions work with structures that must be known and therefore must be declared globally, we conclude that the structure must be declared globally.

By its nature, a function that works with a structure can only accept the same static structures. It means that it is impossible to declare a structure locally so that it has a limited scope and pass it to the function.

Reason: