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

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
int tip=OrderType();
if(OrderSelect(nomber,SELECT_BY_POS,MODE_HISTORY))
You have already been told that the second line of this fragment contains an error: Before the OrderType() function is called, the order must be selected using the OrderSelect() function.
There is an error in line 3: But is there an order with the number 1? If the minimum number was 1, i.e., the account starts with 1, then the maximum number would be equal to the number (let there be 5 orders in total: order numbers 1, 2, 3, 4, 5). But the orders are numbered from 0 - put the cursor on OrdersHistoryTotal and press F1 to see an example. So what is the maximum order number?
Earlier you suggested dividing the date of the month by 7 and rounding, which is done in the second table.
I don't understand your algorithm.
Now here is what I am thinking:
1. Determine the day of the week of the first day of the month.
2. Find out how many days left to the end of the week (was Wednesday (3) to Monday 7-3 = 4).
3. The 5th day is the beginning of the second week
4. then in the loop, we are looking for a week, if the number falls within the range of 5 + 7 * x to 5 + 7 * (x +1), where x - number of week minus one, then we have found the week
But it's complicated, maybe there is an easier way?
Alexey, we are talking about different things. The problem was not to determine which week of the month is the number of the month, but the first day of the week with this name in the month. These are different tasks and, consequently, different solutions.
For 63 years I still can not figure out how to calculate the number of week in the month. For example, in Russia Monday is considered the first day of the week. If the month begins on Sunday, then how do you count Monday? Has the second week begun? Or what??? The question is rhetorical, there is no need to start a polemic about it.
Alexei, we are talking about different things. The problem was not to determine which week of the month the number of the month is in, but whether it is the first day of the week with that name in that month. These are different tasks and, consequently, different solutions.
For 63 years I still do not understand how to count the number of the week in the month. Let us say that in Russia the first day of the week is Monday. If the month begins on Sunday, then how is Monday counted? Has the second week begun? Or what??? The question is rhetorical, there is no need to start a polemic about it.
I see. It's a definite question for me...
Alexei, we are talking about different things. The problem was not to determine which week of the month the number of the month is in, but whether it is the first day of the week with that name in that month. These are different tasks and, consequently, different solutions.
For 63 years I still can not figure out how to calculate the number of week in the month. For example, in Russia Monday is considered the first day of the week. If the month begins on Sunday, then how do you count Monday? Has the second week begun? Or what??? The question is rhetorical, there is no need to start a polemic about it.
You have already been told that the second line of this fragment contains an error: Before the OrderType() function is called, the order must be selected using the OrderSelect() function.
There is an error in line 3: But is there an order with the number 1? If the minimum number was 1, i.e., the account starts with 1, then the maximum number would be equal to the number (let there be 5 orders in total: order numbers 1, 2, 3, 4, 5). But the orders are numbered from 0 - put the cursor on OrdersHistoryTotal and press F1 to see an example. So what is the maximum order number?
if (OrderSelect(1,SELECT_BY_POS,MODE_HISTORY))
int tip=OrderType();
Is it correct now?
if (OrderSelect(1,SELECT_BY_POS,MODE_HISTORY)) - так какой наибольший номер ордера?
int tip=OrderType();
and now is it right?
write a script and after each operator print the information + GetLastError() with Alert() - see the example script above
but you'd better take the error code from the _LastError variable in order to print it, otherwise you may destroy the logic with a light "debug print"
GetLastError() at the same time does an unobvious thing for GetXXX() - it changes its internal state resetting error code to 0.
only for printing it is better to take error code from _LastError variable, otherwise it is possible to destroy logic by a light "debug print"
GetLastError() at the same time does an unobvious thing for GetXXX() - it changes internal state, resetting error code to 0.
well, it's a matter of taste - either store the error code in a variable and reset the error or store it in _LastError for later use
here's the algorithm above to read from the bottom up