How to keep consistency of trade functions

 
// Current order 

// [#1] [#2] [#4] 

 

for (int pos = 0; pos < OrdersTotal(); ++pos)


// when pos is 0, [#1] is selected.

if (OrderSelect(pos, SELECT_BY_POS) == false)

{

}



// (1) long long process... (More than 10 sec) 

// canceled or closed order [#1] [#2] and new order [#5]  => [#4] [#5]

// then next loop (pos is 1)

// OrdersTotal() return 2 and OrderSelect() select [#5] => Warning: [#4] is skipped !

 

How to avoid the above problem ? 
 
What is your problem ?
 
Alain Verleyen:
What is your problem ?

 

Sorry, I changed example of problem. 

 
Taric:

 

Sorry, I changed example of problem. 

Just count down :

for (int pos = OrdersTotal()-1; pos>=0 ; pos--)
 
Alain Verleyen:

Just count down :

 

//  [#1] [#2] [#4]

// pos = OrdersTotal() - 1 (2), OrderSelect() select [#4]

// remove [#1] [#2], add [#5] => [#4] [#5]

// Next loop, pos =  1 then OrderSelect() again select [#4]

 

The problem is that orders was changed while EA process.

Can I lock trade process?

 

you can

SELECT_BY_TICKET

then position shift don't matter.

make sure to check OrderCloseTime() to see if it's a opened or closed order.

 
Marco vd Heijden:

you can

then position shift don't matter.

make sure to check OrderCloseTime() to see if it's a opened or closed order.

 

But, EA don't know ticket Before SELECT_BY_POS loop. 

 

they do if you do

ticket=OrderSend(...


i am not sure what you are trying to do.

probably you only need to improve your code.

 
Taric:

 

But, EA don't know ticket Before SELECT_BY_POS loop. 

You are searching problem where there is not.

If you have a problem, ask a specific question and provide actual code.

Reason: