When you find an open order, why are you setting DeletePending to false again?bool DeletePending=false; for(int z=OrdersTotal()-1; z>=0; z--) { if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType()<OP_BUYLIMIT) { DeletePending=false;
bool DeletePending=false; for(int z=OrdersTotal()-1; z>=0; z--) if( OrderSelect(z,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()<OP_BUYLIMIT) DeletePending=true;
What about a BuyLimit? You just found a pending, just delete it. Put your delete pending check outside the loop.if(OrderType()>OP_SELLLIMIT) { DeletePending=true; y=OrdersTotal(); } if(DeletePending) { if(OrderType()>OP_SELL && OrderType()<=OP_SELLSTOP) { if(!OrderDelete(OrderTicket())) Print("Deleting stop orders"," Ordertype:",OrderType());
if(OrderType()>OP_SELL) if(!OrderDelete(OrderTicket())) Print("Deleting stop orders"," Ordertype:",OrderType());
if(DeletePending) for(int y=OrdersTotal()-1; y>=0; y--)
WHRoeder:
When you find an open order, why are you setting DeletePending to false again?
Thanks for a reply.
I only want it to delete the pending orders if there are NO open orders, if there are open orders then the pending orders must not be deleted? Hence it must return false if there are open orders? If there are no open orders it must carry on through and delete the pending?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hey guys,
Can anyone help with a for loop to close all pending order if and only if there are currently no open orders?
Below is an attempt which I believe is pretty incorrect: