Order Closing Problem

 

Hello,


This ea only opening new BUY/SELL trade but not closing it properly. When new BUY order opened properly. Now condition for closing opened buy order & Opening new SELL order. It is not able to do that. But when I manually close opened buy order & then it open new SELL order. Same error on reverse trade. It open new SELL order properly. At time of closing this opened sell order & opening new BUY order, It is not able to do that. But only done when I close manually this opened sell order. Then it open new BUY order.

Please suggest me possible code solution for this error.


Please download attachment.

Files:
ajnewlideaa.mq4  14 kb
 
I looked at the code but it is poorly written making it difficult to understand. The infinite while loops that require break command execution for exit might be getting stuck. The error handling routine only appears to give alerts and doesn't actually sort out the error.
 

Thanks for replying. Do I need to use "while(ordertotal>0)" in the place of "while(true)" .

And I use same code from tradingexpert.mq4 from metatrader mql guide. only trading system part was changed by me at the place of trading criteria section of code.

I am reading BUY/SELL signals from CSV files. Actually code is working fine for opening new order. But I don't know why it's not closing opened order at the this place :


while(true) // Loop of closing orders .
{
if (Tip==0 && Cls_B==true) // Order Buy is opened..
{ //and there is criterion to close
Alert("Attempt to close Buy ",Ticket,". Waiting for response..");
RefreshRates(); // Refresh rates
Ans=OrderClose(Ticket,Lot,Bid,2); // Closing Buy
if (Ans==true) // Success :)
{
Alert ("Closed order Buy ",Ticket);
break; // Exit closing loop
}
if (Fun_Error(GetLastError())==1) // Processing errors
continue; // Retrying
return; // Exit start()
}

if (Tip==1 && Cls_S==true) // Order Sell is opened..
{ // and there is criterion to close
Alert("Attempt to close Sell ",Ticket,". Waiting for response..");
RefreshRates(); // Refresh rates
Ans=OrderClose(Ticket,Lot,Ask,2); // Closing Sell
if (Ans==true) // Success :)
{
Alert ("Closed order Sell ",Ticket);
break; // Exit closing loop
}
if (Fun_Error(GetLastError())==1) // Processing errors
continue; // Retrying
return; // Exit start()
}
break; // Exit while
}

Reason: