Can`t close all order in terminal - page 2

 
Repions: The problem is in CloseTicket(), i use  Close Price with ask / bid...
I did say:
WHRoeder:
  1. Problem is likely in CloseTicket that you didn't bother to show. Since you aren't selecting only the current chart pair, that had better not be using any predefined variables.
 
WHRoeder:
Repions: The problem is in CloseTicket(), i use  Close Price with ask / bid...
I did say:
WHRoeder:
  1. Problem is likely in CloseTicket that you didn't bother to show. Since you aren't selecting only the current chart pair, that had better not be using any predefined variables.

yeah....Thankss anyway...!!

for me, the problem often occurs because of poor information and poor example at MQL Book & Help file.

 
Repions: for me, the problem often occurs because of poor information and poor example at MQL Book & Help file.

"The problem often occurs because" you aren't thinking things through. If you are on the EURUSD chart and you try to close a USDJPY order, what do you think happens when you use (EURUSD) Bid?

"The problem often occurs because" you are putting blind faith in the examples, instead of thinking things through. Show me the example where it closes multiple orders from multiple pairs.

 

WHRoeder: Show me the example where it closes multiple orders from multiple pairs.


Please .. Give me better solution

bool CloseTicket(int ticket)
  {
   if(STOP_CLOSE_TRADE ) return(false);
   bool result=false;
   int tries=10,pause=500,c;double askbid=-1;
   if(OrderSelect(ticket,SELECT_BY_TICKET)==true)
     {
      if(OrderType()>=2)
        {   // pending order 2-5 
         for(c=0; c<tries; c++) {result=OrderDelete(ticket); if(result==true) break; else { Sleep(pause); continue;} }
        }
      if(OrderType()==0) askbid=bid; else if(OrderType()==1) askbid=ask; 
      if(OrderSymbol()!=Symbol()) askbid=OrderClosePrice();
      for(c=0; c<tries; c++)
        {
         result=OrderClose(ticket,OrderLots(),askbid,Slippage,Violet);
         if(result==true) break;
         else
           {
            Sleep(pause);
            RefreshRates();
            if(OrderType()==0) askbid=bid; else if(OrderType()==1) askbid=ask;
            if(OrderSymbol()!=Symbol()) askbid=OrderClosePrice();
            continue;
           }
        }
     }

   return(result);
  }

Reason: