MetaTrader 4 Build 529 beta released with new compiler - page 17

 
Barbarian:

Did it work before? I can't figure out where you declare the i variable for:


In global variables, I initialise i once and then use it in all loops, it's more convenient and easier ...
 
ALXIMIKS:

Is it supposed to be that when you change the parameters of an indicator that is already running and working, by double-clicking on it,

the indicatordoes not update static variables, therefore, it is not redrawn?


Static variables retain their value when re-initialising the program. The values are not saved only when the program is removed from the chart and rejoined. To reset static variables on reinitialization, I use this construction:

bool g_init;

void OnInit()
{
   g_init = true;
}

void MyFunction()
{
   static int myStatic;
   if (g_init)
   {
      myStatic = 0;
      g_init = false;
   }
}
 
VOLDEMAR:
This is how it works ...

It does not work in this way.


In the second case, the scope of the array declared in the function is a function.

In the code

for(i=Coment-1; i>=1; i--){info[i]=info[i-1]; cv  [i]=cv  [i-1];}info[0]=txt;cv[0]=et;


are you sure you initialize all the array items with values txt and et? Perhaps the last 2 assignments should come before the loop and the loop should be built differently. Or is it such an idea?

 
Scriptong:


Static variables retain their value when reinitialising a programme. The values are not retained only when the program is removed from the chart and re-attached. To reset static variables on reinitialisation, I use the following construction:


So now I have to search through the library and rewrite everything? It's absurd, because everything was fine in 509, and here ......
 
alexvd:


In the second case, the scope of an array declared in a function is a function.

In the code.


Are you sure you are initializing all array elements with txt and et? Probably the last 2 assignments should come before the loop. Or is this an idea?


The text is first shifted one level in the loop, then the null values are assigned to the new text...

These arrays are only used in the functions I presented above ...

Earlier in 509 and earlier builds everything worked in both cases ... Now only in first case ...

 
ALXIMIKS:

What's the point of going through the library and rewriting everything? It's absurd, because everything was fine in 509 and now it's ......


It is simply better to initialise all variables to be used in the code at the beginning of the code...

This simplifies the work, and makes it possible to see and correctly reset the variables at the start of the program and further use ...

 
ALXIMIKS:

Is it supposed to be that when you change the parameters of an indicator that is already running and working, by double-clicking on it,

the indicatordoes not update static variables, that is why it is not redrawn?

As far as I remember it was always like that (in 509 build for sure). It's a bug.

VOLDEMAR:

I've noticed a strange thing on different computers, one with XP and another with W 7

When initializing an array inside a function, the array is not filled with the whole value, only 0 value ...

When initializing an array at global level beyond all functions, the arrays are filled completely as it should be ...

It's been said about it a thousand times - initialize arrays and variables explicitly, don't wait for "heavenly blessings".

In case of local declaration you're just lucky and they don't get rubbish. But I would not count on it.

 
Please note that the new compiler and the new execution environment control code quality many times more tightly. A lot of MQL4 code has been written by third-party developers with their hands down, and now these flaws will be immediately visible.
 

Correct me if I got it wrong.

I use a library function in an indicator, this function declares some static variables that participate in the calculation of the indicator array.

If I want to change the indicator parameters in order to correct indicator calculation (depending on static variables),

pass the flag to the library function that is responsible for reinitialization (you should expand the input parameters of each function that has static variables)

make zeroing of static variables in the body, and do not forget to remove the flag before completing the calculation.

It would be much easier if static variables had some parameter, set during their declaration, responsible for whether these variables will be reset to zero during reinitialization.

 
Renat:
Please note that the new compiler and the new runtime are much stricter in controlling the code quality. A lot of MQL4 code was written by third-party developers and now these flaws will be immediately visible.
Has the MQL4 Handbook (which is in the editor) been also updated accordingly?
Reason: