Questions from Beginners MQL5 MT5 MetaTrader 5 - page 519

 
Vasyl Nosal:

May I ask why this is done?

int total=OrdersTotal();

I should add that if there are a lot of orders, the function will be called at each iteration of the loop, and this is not economical.
 
Sergey Gritsay:
Because while the loop is running, the value ofOrdersTotal(); may change and you may miss an order or the loop body will glitch

Alexey Kozitsyn:
I want to add, if there are a lot of orders, at each iteration of the loop, thefunction will be called, and it's not economical.

Are you both joking or for real?

 
Vasyl Nosal:

Alexey Kozitsyn:
I will add, if there are many orders,the function will be called at each iteration of the loop, and this is not economical.

Are you both joking or for real?

Do you have another point of view?
 

Alexey Kozitsyn:
У Вас другая точка зрения?

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

int i=OrdersTotal()-1

This action is executed once before the first iteration. There is no point in adding anything else. You just make the code larger.

 
Vasyl Nosal:

in this design is possible, but in this design there is a chance of a glitch

for(int i=0; i<total; i++)
 
Sergey Gritsay:

In this design it is possible, but in this one there is a chance of a glitch

:)))))))

On what grounds?

А.

So always go over from the end.

 
Vasyl Nosal:

In this case, yes. And in this case:

for(int i=0; i<OrdersTotal(); i++)
{

}

there is a difference. You didn't specify earlier what you meant.

 
Vasyl Nosal:

:)))))))

On what grounds?

А.

So always go over from the end.

This method is not always appropriate. For example, if you want to go over from the earliest order.
 
kashi_ann:
Yep, so it's just a matter of logic. I was more concerned that apart from the order of actions, you also have to take into account the update time of the data on the server.

The stopping points have of course been used.

I guess I'll have to rewrite the whole thing, it's just nonsense.

I finally figured out what it was all about))))))))

As usual, ridiculously simple))

It's just a wrong application of pending orders) price went lower and the limit order with the buy price was higher))) It just couldn't be placed under those conditions)

Added "stop order" setting and voila, everything is as it should be))))

 
Alexey Kozitsyn:
This method is not always suitable. For example, if you need to overshoot starting with the earliest order.
And when might this be needed?
Reason: