Hopefully simple/quick question about OrderClose()

 

Hi, I'm trying have an open order close, but i get an error saying "invalid lots number for OrderClose function." The same happens for the ticket, "invalid ticket number", unless i save the order as a variable. I imagine there's something obvious that I'm missing and would really appreciate any help.


void OnStart()
  {
//---

   double ticket = OrderSend(NULL,OP_SELL,0.1,Ask,200,Ask+Point*50,Ask-Point*50,NULL,0,0,clrNONE);
   
   double lots = OrderLots();
   double price = OrderClosePrice();
   Sleep(2000);
   

   OrderClose(ticket,lots,price,200,clrNONE);
  }
 

Dear,

  1. Ticket is an integer not double.
    So:
    int ticket = OrderSend(NULL,OP_SELL,0.1,Ask,200,Ask+Point*50,Ask-Point*50,NULL,0,0,clrNONE)

  2. The returned value of OrderClose() must be checked.
    So:
    bool OC = OrderClose(ticket,lots,price,200,clrNONE);

 
Drew Clayman:

Hi, I'm trying have an open order close, but i get an error saying "invalid lots number for OrderClose function." The same happens for the ticket, "invalid ticket number", unless i save the order as a variable. I imagine there's something obvious that I'm missing and would really appreciate any help.


void OnStart()
  {
   int ticket = OrderSend(NULL,OP_SELL,0.1,Bid,200,Ask+Point*50,Bid-Point*50,NULL,0,0,clrNONE);
   Sleep(2000);
   if(!OrderSelect(ticket,SELECT_BY_TICKET)) Print("Error of order selection ", _LastError);
   double lots = OrderLots(); 
   
   if (!OrderClose(ticket,lots,Ask,200)) Print("Error of closing - ", _LastError);
  }
 
double lots = OrderLots();
   double price = OrderClosePrice();
You can not use any Trade Functions until you select an order.
Reason: