Download MetaTrader 5
To add comments, please log in or register
Follow the news. View our company's official channel!
Taric
25
Taric 2015.12.08 22:13 
// 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 ? 
Alain Verleyen
Moderator
30295
Alain Verleyen 2015.12.09 09:18  
What is your problem ?
Taric
25
Taric 2015.12.09 13:30  
Alain Verleyen:
What is your problem ?

 

Sorry, I changed example of problem. 

Alain Verleyen
Moderator
30295
Alain Verleyen 2015.12.09 13:38  
Taric:

 

Sorry, I changed example of problem. 

Just count down :

for (int pos = OrdersTotal()-1; pos>=0 ; pos--)
Taric
25
Taric 2015.12.09 14:16  
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?

Marco vd Heijden
Moderator
4505
Marco vd Heijden 2015.12.09 14:23  

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.

Taric
25
Taric 2015.12.09 14:31  
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. 

Marco vd Heijden
Moderator
4505
Marco vd Heijden 2015.12.09 14:41  

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.

Alain Verleyen
Moderator
30295
Alain Verleyen 2015.12.09 17:32  
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.

/
To add comments, please log in or register