Features of the mql5 language, subtleties and tricks - page 182

 
Konstantin Nikitin:

For example, I delete all objects on my VDS. I just don't want to overload the schedule. And there's no need for them there. I use globals. So it all depends on the situation.

Look, I don't like them for a reason:

  1. It's a question of atomicity of operations with them. The docs are silent about it, although in fact it is an object and operations with them are not atomic, and reading/writing double itself in x86 is, if I'm not mistaken, two instructions.
  2. The accessibility of variables outside the program.
If point 1 is more of a grumble about the quality of documentation, point 2 is serious.
 
Vladimir Simakov:

Look, there's a reason I don't like them:

  1. The question of atomicity of operations with them. The docs are silent about it, although, in fact, it is an object, and operations with them are not atomic, and reading/writing double in x86 itself is, if I'm not mistaken, two instructions.
  2. The accessibility of variables outside the program.
If item 1 is more of a grumble concerning the quality of documentation, item 2 is serious.

Well, there's no need to read it. You can use GlobalVariableCheck to check if the variable is there or not. You can do the same with objects.
So you only need to create/check/delete a variable.

 

Vladimir Simakov:

2. Availability of variables outside the program.

no problem, all functions that work with global variables have a return value - the result of the operation

there is a synchronization toolhttps://www.mql5.com/ru/docs/globals/globalvariablesetoncondition , it's not much, but use what you are offered

But the big inconvenience is the data type - only double , I do not like double , even if only ulong could be used, and the organization of name / value ---> string / double causes a desire to swap - to write data in string and key in double - more for one operation can be written / read

but having estimated all this "stuff" You may write them into binary files, i.e. total freedom and no uncertainties.

one probably needs to know how to work with them

@fxsaber showed examples of working with any typeshttps://www.mql5.com/ru/forum/320395/page6#comment_12910394

 
Konstantin Nikitin:

Well, there's no need to read. You can simply use GlobalVariableCheck to check if the variable exists or not. You do the same with objects.
So, you only need to create/check/delete a variable.

Yes, a trivial naming conflict and the string in the other robot

GlobalVariableDel(yourValueName);

will lose your deposit))))

Say that the name will be unique, that the other robot will never be there, that the child/wife/friend/drunkard will never come near the battle terminal))) Agreed, but the probability is not zero, which means the code becomes unreliable.

 
Vladimir Simakov:

Yes, it's a trivial naming conflict and the other robot's line

will drain you of your deposit)))

You will say that the name will be unique, that the other robot will never be there, that the child/wife/friend/drunk himself will never come near the battle terminal))) Agreed, but the probability is not zero, which means the code becomes unreliable.

Bullshit and fantasy

An EA on money ALWAYS runs from a separate terminal, on its own VDS (or even server) and no one ever messes with it.

 
Maxim Kuznetsov:

Bullshit and fantasy

An EA on the money ALWAYS runs from a separate terminal, on its own VDS (or even server) and no one ever messes with it.

What do you mean ALWAYS? Today - always, tomorrow you may calculate differently. And not everyone seems to agree with you.

I pointed out the real danger of using global variables of the terminal. This is neither good nor bad - it's a given that developers gave us, we just need to be aware of it and take it into account.

The same string

GlobalVariablesDeleteAll();

...made in any script and oops...

 

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql5, tips and tricks

Vladimir Simakov, 2020.05.24 17:02

The same string

GlobalVariablesDeleteAll();

...made in any script and oops.

The same is with the graphical objects.

ObjectsDeleteAll(...


Only the EA resources cannot be changed by other programs.

 

Colleagues, please help me make a macro, if at all possible.

I need to dynamically declare a two-dimensional array. And the second dimension must also be changed. This is something like this loop:

for(int would_be_size2=0;would_be_size2<5;would_be_size2++)
    {
     double d_array[][would_be_size2];
     int size2=ArrayRange(d_array,1);
    }

Of course, the compiler will balk at this:

'[' - invalid index value       t7.mq5  20      22

I would like to see a macro like the following:

#define  CREATE_MARRAY(type,arr_name,size2) (type arr_name[][##size2])

Instead of a line:

double d_array[][would_be_size2];

Thank you.

 
Denis Kirichenko:

Colleagues, please help me make a macro, if at all possible.

I need to dynamically declare a two-dimensional array. And the second dimension must also be changed. This is something like this loop:

Of course, the compiler will balk at this:

I would like to see a macro like the following:

Instead of a line:

Thank you.

But creating an array of sufficient (maximum) size outside the loop is hindered by politics ? :-)

The above approach (recreating the array in the loop every time) does not win anything in terms of speed or memory consumption.

 
Denis Kirichenko:

I would like to see a macro similar to this:

It won't work.