bool res=OrderClose(Ticket,Lots,CurrentPrice,Slippage,Red); //If the close was successful print the resul and exit the function if(res){ Print("TRADE - CLOSE SUCCESS - Order ",Ticket," closed at price ",CurrentPrice); break; } //If the close failed print the error else{ int Error=GetLastError(); string ErrorText=GetLastErrorText(Error); Print("ERROR - CLOSE FAILED - error closing order ",Ticket," return error: ",Error," - ",ErrorText); }
//----how can i solve this warning.....
return value of orderclose should be checked,
void closeallprofitable() { //--- Print("profit alert ea closed at "+DoubleToStr(profit,0)+" $"); if(!enablecloseall) {Alert("please enable close all");} if(enablecloseall) { int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { if(OrderSelect(i, SELECT_BY_POS) == true) if(OrderProfit() < minimumprofit) continue; bool result = false; if((OrderProfit() > minimumprofit) && OrderType() == OP_BUY) { OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); } if((OrderProfit() > minimumprofit) && OrderType() == OP_SELL) { OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); } } } } //------ //------ void closeallprofitable() { //--- Print("profit alert ea closed at "+DoubleToStr(profit,0)+" $"); if(!enablecloseall) {Alert("please enable close all");} if(enablecloseall) { int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { if(OrderSelect(i, SELECT_BY_POS) == true) if(OrderProfit() < minimumprofit) continue; bool result = false; if((OrderProfit() > minimumprofit) && OrderType() == OP_BUY) { result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); } if((OrderProfit() > minimumprofit) && OrderType() == OP_SELL) { result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); } } } } //------ //------
You can solve it by checking the return value of OrderClose, obviously! For example, like this:
MQL4:bool res=OrderClose(Ticket,Lots,CurrentPrice,Slippage,Red); //If the close was successful print the resul and exit the function if(res){ Print("TRADE - CLOSE SUCCESS - Order ",Ticket," closed at price ",CurrentPrice); break; } //If the close failed print the error else{ int Error=GetLastError(); string ErrorText=GetLastErrorText(Error); Print("ERROR - CLOSE FAILED - error closing order ",Ticket," return error: ",Error," - ",ErrorText); }
thanks,,,and i belief it applies to other warnings for other functions,like orderdelete....You can solve it by checking the return value of OrderClose, obviously! For example, like this:
MQL4:bool res=OrderClose(Ticket,Lots,CurrentPrice,Slippage,Red); //If the close was successful print the resul and exit the function if(res){ Print("TRADE - CLOSE SUCCESS - Order ",Ticket," closed at price ",CurrentPrice); break; } //If the close failed print the error else{ int Error=GetLastError(); string ErrorText=GetLastErrorText(Error); Print("ERROR - CLOSE FAILED - error closing order ",Ticket," return error: ",Error," - ",ErrorText); }
Yes, of course. They all may fail and it's a good idea to let the trader know about why it failed. Or it's even a better idea to code it so that it tries to Open/Close/Delete/Modify an order in a loop for up to N attempts before it gives up.thanks,,,and i belief it applies to other warnings for other functions,like orderdelete....
if (!OrderSelect(ticket, SELECT_BY_TICKET)) { Print("Error selecting order with ticket #", ticket, ": ", GetLastError()); continue; // If this is in the cycle and you want to avoid working with the order that you failed to select. }