hello friends!
i have a pending function that should close one pending order while the other order active.
instead its closing the 2 pending immediately (one of them should be hit first , and after that the function need to close the other one.)
This will not work:
if (type_active == OP_BUY || OP_SELL )
https://www.mql5.com/en/forum/141790
While you are in the first loop using an index of i you start a second loop using index i what you think is going to happen with the first loop ?
This will not work:
https://www.mql5.com/en/forum/141790
While you are in the first loop using an index of i you start a second loop using index i what you think is going to happen with the first loop ?
does not cloing the pending.
the code:
void ClosePendingOrder(string symbol ) { int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type_active = OrderType(); if ((type_active == OP_BUY) ||(type_active== OP_SELL ))<<<<<---change formation ---- { total = OrdersTotal(); for(int j=total-1;j>=0;j--)<<<<<<<------changed to j ----- { OrderSelect(j, SELECT_BY_POS); int type = OrderType(); bool result = false; switch(type) { //Close pending orders case OP_BUYLIMIT : case OP_BUYSTOP : case OP_SELLLIMIT : case OP_SELLSTOP : result = OrderDelete( OrderTicket() ); } if(result == false) { Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );<<<<--add thise to--- // Sleep(3000); } } } } return(0); }
thanks!
does not cloing the pending.
You need to read your code and work through it for each value of the loops . . . you have some glaring issues which you need to be able to see for yourself. For example, what if type is OP_SELL what happens with your switch statement ? and then what is the value of result ?
Did you look up error 4008 ? what does it mean ?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello friends!
i have a pending function that should close one pending order while the other order active.
instead its closing the 2 pending immediately (one of them should be hit first , and after that the function need to close the other one.)
the code:
thx!