trouble with OrderClose()

 
   int cnt, total;          total=OrdersTotal();

   for(cnt=0;cnt<total;cnt++)         {

      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

          
      if( OrderType()==OP_BUY  &&  Bid-OrderOpenPrice()  >Point*TakeProfit)   {
      
           OrderClose(cnt, OrderLots(),Bid, 3, CLR_NONE)  ; 
      

Why is this not closing my order?   When an order meets the "if" criteria, it does not close.   

Any help would be appreciated...     thanks 

 
mrchuckw:

Why is this not closing my order?   When an order meets the "if" criteria, it does not close.   

Any help would be appreciated...     thanks 

Read this:  https://www.mql5.com/en/forum/143996/page2#808562  and especially the documantation for OrderClose(),  what is the first parameter it takes ?  and what are you passing to it ?

Does your OrderSelect() work ?  read this:   What are Function return values ? How do I use them ?

 

RaptorUK...   thanks... I read it, and fixed it (see code) and now it closes the orders perfectly...   but the next part... the send mail, I get the "Mail: Not enough space..." error.

the Mail function

void check.order()     {


   int cnt, total;   string ordertyp;            total=OrdersTotal();

   for(cnt=0;cnt<total;cnt++)         {

      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          
      if( OrderType()==OP_BUY  &&  Bid-OrderOpenPrice()  >Point*TakeProfit)   {
      
           OrderClose(OrderTicket(), OrderLots(),Bid, 3, CLR_NONE)  ; 
      
           if(textclose==1){   ordertyp="BUY";
           
           SendMail("CLOSED TRADE "+version,
           "\n  OpenTime: "+TimeToStr(OrderOpenTime())+
           "\n Close Time: "+TimeToStr(OrderCloseTime())+
           "\n Order Type   "+ordertyp+ "   Profit "+DoubleToStr(OrderProfit(),2)+
           "\n Account Equity     "+DoubleToStr(AccountEquity(),5)
            );              }                                                                                                     }

should only happen when I close an order...  what is wrong with my code? 

 
mrchuckw:

RaptorUK...   thanks... I read it, and fixed it (see code) and now it closes the orders perfectly...   but the next part... the send mail, I get the "Mail: Not enough space..." error.

the Mail function

should only happen when I close an order...  what is wrong with my code? 

Did you test  that email from the terminal is working ?  in  Tools>Options>Email there is a Test button,  use it and make sure that you have email setup correctly,  for example,  you cannot send directly to gmail. 

Your code will not function correctly if you have more than one order to close,  read this:   Loops and Closing or Deleting Orders

As I already said . . . .   Does your OrderSelect() work ?  read this:   What are Function return values ? How do I use them ? 

 
RaptorUK:

Did you test  that email from the terminal is working ?  in  Tools>Options>Email there is a Test button,  use it and make sure that you have email setup correctly,  for example,  you cannot send directly to gmail. 

Your code will not function correctly if you have more than one order to close,  read this:   Loops and Closing or Deleting Orders

As I already said . . . .   Does your OrderSelect() work ?  read this:   What are Function return values ? How do I use them ? 


Thanks for the references.   But what fixed it was logging out of the mt4 and getting back in.
 
mrchuckw:

Thanks for the references.   But what fixed it was logging out of the mt4 and getting back in.
Are you going to address the issues in your code ?  you don't check that the OrderSelect() worked and you aren't checking the return value from the OrderClose() and reporting any errors . . .
Reason: