[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 493
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
I am currently learning how to write one EA in terms of understanding the source code, as the EA is very well written.
But one thing is strange there.
Why is the number of all orders assigned toOrdersTotal() - 1, and not justOrdersTotal()?
Because if we have 0 orders in total, then the value of total will be -1 instead of 0.
Look where total is used afterwards. Most likely, then the loop goes through the orders for (i=0; i<=total; i++).
By the way, yes... I've already added the full code of this function above:
I figured it would be more logical not to write it this way:
and then set the loop like this:
Right? Just somehow it's not perceived very well when the counter of number of positions from zero... it's not logical and, therefore, why confuse yourself...
By the way, yes... I've already added the full code of this function above:
I figured it would be more logical not to write it this way:
and then set the loop like this:
Right? It's just that the counter of the number of positions from zero is not perceived as such... It's not logical and, therefore, there is no reason to confuse ourselves...
You have to go to zero, not one, to search for orders.
A pro once explained to me that we are searching an array of orders, and it's better to start the search with a higher number. In the array, the first element has index 0 (zero), so we shouldn't reach 1 and this is also the reason why we should go to OrdersTotal() - 1, instead of simple OrdersTotal().
I have the order search done this way:
You have to go all the way down to zero, not one, in order to search for orders.
A pro once explained to me that it's an array of orders and then yes, it's better to start with a bigger digit. In the array, the first element has an index of 0 (zero), so not to 1 and also for this reason we need OrdersTotal() - 1, not just OrdersTotal().
It is very interesting. And the first thing I did was to open the textbook and try to find the answer there. And thenhttps://book.mql4.com/ru/trading/ordermodify saw how the tutorial made the overflow:
This is the factor that misled me...
Very interesting. And the first thing I did was to open the textbook and try to find the answer there. And thenhttps://book.mql4.com/ru/trading/ordermodify I saw how the textbook was overdone:
That's the factor that misled me...
Didn't you notice the next line?
Didn't you notice the next line?
No. But somehow it is crooked to write it. I don't want to criticise the textbook, but... it's much more adequate to count from 0 rather than -1. Otherwise you could have already started from -30...
Aspaladin80 pointed out above, from 0 the value of arrays would be more adequate than from -N.
No. But somehow it is crooked to write it. I don't want to criticise the textbook, but... it's much more adequate to count from 0 rather than -1. Otherwise we could have already started from -30...
Aspaladin80 pointed out above, from 0 the value of arrays would be the most adequate, if from -N.
Now think logically!
These variants are identical, because if i = 0, we need to look from 1 to OrderTotal(), i.e. from 0+1 to OrderTotal() - 1+1 (+1, because i++ is at the end of the for statement) The same in the tutorial, only written from 1 to OrderTotal() and, in order not to count from 2 to OrderTotal()+1, inthe OrderSelect function the textbook author added -1 to i. Got it?
By the way, as many programmers as there are, there are almost as many variants. Everyone has his own vision, his own handwriting!
No. But somehow it is crooked to write it. I don't want to criticise the textbook, but... it's much more adequate to count from 0 rather than -1. Otherwise you could have already started from -30...
Aspaladin80 pointed out above, 0 would be more adequate for arrays than -N.
If you are interested in the search of orders, I can suggest the following scheme:
No. But somehow it is crooked to write it. I don't want to criticise the textbook, but... it's much more adequate to count from 0 rather than -1. Otherwise you could have already started from -30...
Aspaladin80 pointed out above, 0 would be the most appropriate way to read arrays, as opposed to -N.
And now think, including logic!
These variants are identical, because if i = 0, we try from 1 to OrderTotal(), i.e. from 0+1 to OrderTotal() - 1+1 (+1, because i++ is at the end of the for statement) And the same is in the textbook, only from 1 to OrderTotal() and in order not to count from 2 to OrderTotal()+1, we add -1 to i in OrderSelect function. Got it?
Of course, I understand. But I haven't seen orders analyzed in such a way before:
usually just without ==true... I even liked this point. Although, it is interesting, I had never encountered such a method in other EAs. I understand the logic, but still.