Errors, bugs, questions - page 168

 
Manov:

You have"possible use of uninitialised variable 'local_low'".

What does it say if

If the variable is initialized with anything, the warning disappears. But as you may see for yourself, initialization of the 'local_low' variable in this code fragment is unnecessary. So the warning doesn't interfere with life at all.
 
Renat:

Re-read my answers from the point of view of a software company manager who has brought many software projects to market.

Otherwise, remaining at the level of "any programmer", you will not understand what the mistake is.

:) Since I will never become the head of a software company, I will forever remain at the level of "any programmer" (i.e. an amateur programmer, in my understanding).

...And since the amateur programmer never gets a logical description of the error, he concludes that either there is simply no error in his bit of code or the error is so complicated that nobody can describe it in the language of logic. At this point, we can consider that both sides understand each other, the question is over.

 
Yedelkin:
If the variable is initialized with anything, the warning disappears. But, as you can see for yourself, initialization of the variable local_low is redundant in this piece of code. So the warning doesn't interfere with life at all.
A concrete code is probably yes. but the compiler will have to be as"foolproof" as possible.
 
So, the monitor flamed up and told the programmer: never hide initialization behind a condition, never use a loop variable after the loop body, check division by zero, don't multiply entities unnecessarily, don't write if (a==true) ...
 
Manov:
... The compiler will have to be as"foolproof" as possible.
I'm not arguing with that. It's a useful warning. The more of these warnings you have, the better you will understand your own code.
 
Vigor:
... do not write if (a==true) ...

By the way, in spring I had training Expert Advisors, in which, having read a lot of literature, I inserted conditions of if(a) type. But experts started working only after I changed these conditions to conditions like if (a==true). Now I can hardly get out of this habit.
 
Yedelkin:

But because of the use of bool-variable interrupcion in line 9 right after initialization of variable local_low in line 8, it turns out that in line 15 the variable local_low will be guaranteed to be initialized. So at this point, the warning "possible use of uninitialized variable 'local_low'" does not mean "guaranteed" but just possible presence of a pass-through branch in which the variable is uninitialized.
In your example, if Ac-k=0 , the for operator will not be executed at all and local_low will be guaranteed uninitialized. Or is it wrong?
Документация по MQL5: Основы языка / Операторы / Оператор цикла for
Документация по MQL5: Основы языка / Операторы / Оператор цикла for
  • www.mql5.com
Основы языка / Операторы / Оператор цикла for - Документация по MQL5
 

If we send a request to modify a position with the same stops, we will get an error. But if you send a request to modify a pending order with the same parameters, the request will be executed. Is this the way we have planned it and we don't need to check the parameters for changes?

Why clog the server with unnecessary requests, for example, in case of an error in the Expert Advisor or incorrect logic of its operation?

Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - Документация по MQL5
 
Valmars:
In your example, if Ac-k=0 , then the for statement will not be executed at all and local_low is guaranteed uninitialized. Or is it wrong?

That's exactly right. If Ac-k<=1, the for operator must not be executed at all and the local_low variable is guaranteed to remain uninitialized. But since the bool-variable interrupcion remains false (line 3), by virtue of the condition in line 13, the uninitialized variable local_low will never (should never) be used in calculations. In particular, an expression with the variable local_low from line 15 should not be evaluated [unless, of course, the if statement works exactly as stated in the help:) ].

In other words, if the variable local_low is guaranteed to be uninitialized, it is also guaranteed not to (should not) be used in calculations.

 

void Graf()
{
if(ObjectFind(0, "H")<0) ObjectCreate(0, "H",OBJ_HLINE
,0,0,h,0);
if(ObjectFind(0, "L")<0) ObjectCreate(0, "L",OBJ_HLINE,0,0,l,0)
; ObjectSetDouble(0, "H",OBJPROP_PRICE,h)
; ObjectSetDouble(0, "L",OBJPROP_PRICE,l)
;
string bal = DoubleToString(AccountInfoDouble(ACCOUNT_BALANCE),2)
;string equ = DoubleToString (AccountInfoDouble(ACCOUNT_EQUITY),2)
; string spread = DoubleToString(((Ask-Bid)/_Point),0)
; string space = ""
; string info= bal+space+equ+space+spread
;
if (ObjectFind(0, "info")<0) ObjectCreate(0, "info",OBJ_LABEL,0,0,0)
; ObjectSetInteger(0, "info",OBJPROP_XDISTANCE,0)
;ObjectSetInteger(0, "info",OBJPROP_YDISTANCE,15)
; ObjectSetString(0, "info",OBJPROP_TEXT,info)
;ObjectSetInteger(0, "info",OBJPROP_FONTSIZE,36)
; ObjectSetInteger(0, "info",OBJPROP_COLOR,Maroon)
; return
; }

Here is a piece of code. The function prints balance, equity and spread values on every tick. But the information is shown for some reason, not for the previous tick... Please help me to understand why ? In MT4 similar code changes values with every new tick, and in MT5 with a new tick information is displayed for previous tick.
Reason: