Question about Expert Advisor lifespan.

 
I am developing an expert advisor, which has a funciton to close several positions if a condition is met. However, if there are more then say 5 positions, and it doesn't finish closing them before the next tick comes in, it stops closing the positions. I am assuming that the Start function gets called again, and it is somehow interferring with the previous Expert advisor.
If this is the case, what can I do to prevent subsequent ticks from causing my closing function to halt?
 

Incoming tick cannot interrupt EA execution.

BTW for closing positions You need to use backward loop

for(cnt=OrdersTotal(); cnt>=0; cnt--)

 
LanceWynn:
However, if there are more then say 5 positions, and it doesn't finish closing them before the next tick comes in, it stops closing the positions.
Probably it stops closing because of slippage. Check the slippage parameter of OrderClose(), and call RefreshRates() function before calling OrderClose().
 
fireflies:
LanceWynn:
However, if there are more then say 5 positions, and it doesn't finish closing them before the next tick comes in, it stops closing the positions.
Probably it stops closing because of slippage. Check the slippage parameter of OrderClose(), and call RefreshRates() function before calling OrderClose().

I am looping backward (that took me a couple tries to figure that out, for some reason, it closed about half of the orders (It would skip every other one...)) I have added the RefreshRates to the function, and it seems to have fixed the issue, thanks a ton!
 
stringo:

Incoming tick cannot interrupt EA execution.

BTW for closing positions You need to use backward loop

for(cnt=OrdersTotal(); cnt>=0; cnt--)

Maybe I have missed above concept in MQL4 docs. If not documented, is this not VIP info?

I read many https://www.mql5.com/en/articles/mt4/ articles and some use 0..OrdersTotal()-1 and others use OrdersTotal()-1..0

without further clarification + background info, it is not possible to understand your comment.

Could you please explain why you say this? ie, some background info to hang your comment onto and make sense of it would be appreciated.

If is FILO queue/stack I could understand.

However, if must do this then orders in trade pool must have positional significance, yes?

This would then indicate that closing order 'positioned' within[notAtTopOf] trade pool queue is not allowed and also that many https://www.mql5.com/en/articles/mt4/ are incorrect.

 
ukt:
stringo:

BTW for closing positions You need to use backward loop

for(cnt=OrdersTotal(); cnt>=0; cnt--)

Maybe I have missed above concept in MQL4 docs. If not documented, is this not VIP info?

I read many https://www.mql5.com/en/articles/mt4/ articles and some use 0..OrdersTotal()-1 and others use OrdersTotal()-1..0

without further clarification + background info, it is not possible to understand your comment.

Could you please explain why you say this? ie, some background info to hang your comment onto and make sense of it would be appreciated.

I've never had concerned on this as usually I have only one or two open orders at a single time, so no need to have it in a loop.
But for those who maintains many open orders, this small thing becomes important.
Myself prefers a safer and clearer structure below
int total = OrdersTotal();
// then the following structure be the same as...
for( int count = 0; count < total; count++ ) ...
 
// ...the same as this one below...
for( int count = total-1; count >= 0; count++ ) ...
The problem is at the repeated calls to OrdersTotal() DURING OrderClose()-ing makes the value of OrdersTotal() changes!!!