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

 
MakarFX #:
What's wrong with this one?

yes to everyone, it doesn't fit the question-answer format and it's stupid formatting, you can't insert a line of code into the text without taking it to the next line, you can't quote a piece of code properly: the whole message is pasted out of pocket.

 
Nerd Trader #:

From one, OrdersTotal will return zero when there are no orders. But for some reason.

for ( int i = OrdersTotal() ; i > 0 ; i -- )

gives an infinite loop, and so >= not.

Is there another more convenient platform for communicating about mql?

This is the website of the developers of the platform and MQL language.

Where else would you get the most accurate answers?

And your question is from the area of misunderstanding how to work with arrays.

 
Aleksei Stepanenko #:

the loop is not set correctly:

it should be like this:

Why? Everyone writes with equals, but is that right? Why do we need one iteration of the loop if the positions are 0 ?
 
Nerd Trader #:

From one, OrdersTotal will return zero when there are no orders. But for some reason.

for ( int i = OrdersTotal() ; i > 0 ; i -- )

gives an infinite loop and so >= not.

s.w. is there another more convenient platform for mql communication?
Why does it give an infinite loop? it doesn't give me one, only i have mql5
 
No, it's OK. If there are no positions, then i=OrdersTotal()-1 will be equal to -1. And the loop condition i>=0 will not be executed immediately. And the program will not enter the loop.
 
is greater than or equal to, because the first element of the array must also be counted, and its index in the array is zero.
 
Aleksei Stepanenko #:
is greater than or equal to, because the first element of the array also needs to be taken into account, and its index in the array is zero.
Oh, right, thanks. But it's a crutch, of course. Just like the entire mql, of course.
 

Hello!

Variables are declared as follows

input  string startHour ="00:20";
input  string endHour ="23:40";
datetime startTime, endTime;

In the mql4 code, the line is like this

startTime=StringToTime(StringConcatenate(TimeToString(TimeCurrent(),TIME_DATE)," ",startHour));
endTime=StringToTime(StringConcatenate(TimeToString(TimeCurrent(),TIME_DATE)," ", endHour));

The mql5 compiler gives the error'(TimeToString' - variable expected),warning(implicit conversion from 'number' to 'string')

Could you please tell me how to correct it?

 
grimc124 #:

...

Can you please tell me how to fix it?

Do not duplicate code (principle DRY = Don't Repeat Yourself) Use functions. For example:

datetime SetTime(datetime dtime, string stime) {
    return StringToTime(TimeToString(dtime, TIME_DATE) + " " + stime);
}

Any invalid string is converted to zero time

 
Artyom Trishkin #:

This is the website of the developers of the platform and the MQL language.

Where else would you get the most accurate answers?

Your question represents a lack of understanding of how to work with arrays.

OrdersTotal, at 1 order returns 1 and not 0. When there are 0 orders, it returns 0.

"This is a website of the developers of the platform and MQL language. Where else would you get the most accurate answers? "

- Just because it's a developer's resource doesn't mean it's the right place to do it, as there are resources specifically designed for the question-answer format.

Reason: