Can we close the Order Partially???

 

Hi All,


I just want to know can we close the part of the order.. ie profit-booking of 50% of the holdings, when profit is 10 pips...

Could someone please tell me how to achieve this...


I tried doing.... OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Ask,3,Green);


But I'm getting lot of following errors..

OrderClose error 4051
Invalid ticket for OrderClose function


SO I got a doubt can we close like this and hold the other half.... Please suggest me....


Regards,

Ganesh

 
codersview wrote >>

Hi All,

I just want to know can we close the part of the order.. ie profit-booking of 50% of the holdings, when profit is 10 pips...

Could someone please tell me how to achieve this...

I tried doing.... OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Ask,3,Green);

But I'm getting lot of following errors..

OrderClose error 4051
Invalid ticket for OrderClose function

SO I got a doubt can we close like this and hold the other half.... Please suggest me....

Regards,

Ganesh

It is no problems to closing half of you holding in this case but what is in your variable ticket? I think it is not the correct ticket number. Usually OrderClose() will use OrderTicket() to take back the ticket number. Please have a check.

 

Hi Brother,


I tried that one also... even then I'm getting that error... Could u please quote some example of the usage of partial closing orders...

 

Dear codersview

Please create a new bank EA and put following code into and test it with Strategy Tester and see the result. It is tested on FXDD server, other broker server are expected to work too. Have fun.

int start()
  {
//----
      int ticket, total, i;
      total = OrdersTotal();
      if(total < 1)
         ticket = OrderSend(Symbol(), OP_BUY, 1, Ask, 3, 0, 0, NULL, 123, 0, Blue); // open order for 1 lot in size
      for (i=0; i<total; i++){
         OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
         if(Bid+10*Point > OrderOpenPrice() || Ask-10*Point < OrderOpenPrice())
               OrderClose(OrderTicket(), 0.5, Bid, 3, Green); // close order for 0.5 lots in size
      }             
//----
   return(0);
  }

bro.

P.S. Did you check the minimium lot size of your broker provide? Some server only provide a minimium lot size = 1 and you will not possible to close order at 0.5 lots in size if it is.

Reason: