Questions from Beginners MQL5 MT5 MetaTrader 5 - page 495
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
On the first case is solved - put in brackets for two comparisons and it does not swear - was there a logical error - i.e. the results of the comparison could be replaced because of the "or"?
There remains an open question with the second expression - what is wrong there - any ideas?
The first case is solved - put in brackets two comparisons and it does not swear - was there a logical error - i.e. comparison results could be replaced because of "or"?
There is still an open question concerning the second expression - what is wrong there - any ideas?
Remember that the check of a condition in the new mql4 is not performed completely. I.e. in the condition
if(Low[X]>PriceBuy && High[X]>PriceBuy ||
Low[X]<PriceBuy && High[X]<PriceBuy)
If Low[x] is not larger than PriceBuy, then no further check will be performed. This is what the error description tells us about. Correspondingly, if the first pair is enclosed in brackets, the second pair of conditions will be checked if it fails.
Second question.
for(calc_day;calc_day>0; calc_day--)
What is calc_day equal to? May it be less than zero? The compiler doesn't know what's in the logic... That's why it warns about a possible ineffective loop.
Remember that condition checking in the new mql4 is not performed completely. I.e., in the condition
if(Low[X]>PriceBuy && High[X]>PriceBuy ||
Low[X]<PriceBuy && High[X]<PriceBuy)
If Low[x] is not greater than PriceBuy, no further check will be performed. This is what the error description tells us about. Correspondingly, if the first pair is enclosed in brackets, the second pair of conditions will be checked if it fails.
Thank you for the answer!
Surprised - as visually the logic has always worked correctly, hmmm...
Second question.
for(calc_day;calc_day>0; calc_day--)
What is calc_day equal to? May it be less than zero? The compiler doesn't know what is in the logic... That's why it warns about a possible ineffective loop.
Thanks for the reply!
Surprised - as visually the logic has always worked correctly, hmmm...
Before 6** builds it was like that, checked the whole chain of conditions and everything worked, but now everything has changed. And in old builds in this case condition is ambiguous. How is it designed?
if( (Low[X]>PriceBuy && High[X]>PriceBuy) || (Low[X]<PriceBuy && High[X]<PriceBuy) )
Or did it?
if(Low[X]>PriceBuy && ( High[X]>PriceBuy) || (Low[X]<PriceBuy ) && High[X]<PriceBuy)
A human brain can figure it out, but what is a compiler to do? It doesn't have a brain.
-Aleks-:
The number calc_day is always greater than 0. Other values don't cause code to be called.Tell it to the compiler...
Up to build 6** it was like that, the whole chain of conditions was checked and everything worked, but now everything has changed. And in old builds the condition is ambiguous in this case, too. How is it designed?
if( (Low[X]>PriceBuy && High[X]>PriceBuy) || (Low[X]<PriceBuy && High[X]<PriceBuy) )
or is that it?
if(Low[X]>PriceBuy && ( High[X]>PriceBuy) || (Low[X]<PriceBuy ) && High[X]<PriceBuy)
A human brain can figure it out, but what is a compiler to do? He doesn't have a brain...
Tell it to the compiler...
Convincing - I'll be more vigilant.
How do I tell the compiler? Write it, but will it understand?
if (calc_day<0) calc_day=calc_day*(-1);
It was like that before 6** builds, the whole chain of conditions was checked and everything worked, but now everything has changed. Yes and in old builds in this case condition ambiguity. How is it designed?
if( (Low[X]>PriceBuy && High[X]>PriceBuy) || (Low[X]<PriceBuy && High[X]<PriceBuy) )
or is it?
if(Low[X]>PriceBuy && ( High[X]>PriceBuy) || (Low[X]<PriceBuy ) && High[X]<PriceBuy)
A human brain can figure it out, but what is a compiler to do? He doesn't have a brain...
Tell it to the compiler...
check operator precedence for possible error; use parentheses to clarify precedence - this is not an error. It is a warning. It occurs in old codes.
They added it for the user rather than for the compiler. The compiler is guided by operation priorities. Everything is clear there. Priority of && is higher than that of ||. That's why the brackets should be arranged in this way
if( (Low[X]>PriceBuy && High[X]>PriceBuy) || (Low[X]<PriceBuy && High[X]<PriceBuy) )
Update: In this case both for MT4 and MT5 the priority is the same.
Convincing - I'll be more vigilant.
How do I tell the compiler? Write it, but will it understand?
if (calc_day<0) calc_day=calc_day*(-1);
check operator precedence for possible error; use parentheses to clarify precedence - this is not an error. It is a warning. It occurs in old codes.
We added it for the user rather than for the compiler. The compiler is guided by operation priorities. Everything is clear there. Priority of && is higher than that of ||. That's why the brackets should be arranged in this way
if( (Low[X]>PriceBuy && High[X]>PriceBuy) || (Low[X]<PriceBuy && High[X]<PriceBuy) )
Update: In this case both for MT4 and MT5 the priority is the same.
Well in essence, yes, the warning is not an error. But how will the initial variant work if( Low[X]>PriceBuy && High[X]>PriceBuy || Low[X]<PriceBuy && High[X]<PriceBuy )? Or is it a bummer to put a couple of brackets?
Convincing - I'll be more vigilant.
How do I tell the compiler? Write it, but will it understand?
if (calc_day<0) calc_day=calc_day*(-1);
Well, in essence, yes, the warning is not an error. But how will the initial variant work if( Low[X]>PriceBuy && High[X]>PriceBuy || Low[X]<PriceBuy && High[X]<PriceBuy )? Or will it fail to put a couple of brackets?
It will work the way I wrote above.
The compiler warns the user not to be lazy and put parentheses to avoid possible non-obvious errors.