How can I get a new ticket?

 

Dear all,

This is my first message in this forum because I am an amateur MQL4 programmer. I've created my firsrt EA, but I've got a problem. I want to partially close an order, an this creates a new ticket number after the first TP is reached. Could someone please tell me how can I find the new ticket number created for the remaining order?

Thank you very much in advance.

mesigual

 

Something like this might do the trick ... I recommend you test it.

int start(){
//----------
int Ticket;
for(int i=OrdersTotal()-1;i>=0;i--){
  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
    if(OrderTicket()>Ticket){
      Ticket=OrderTicket();
    }
  }
}
//----------
return(Ticket);}

You can create a User Defined Function like the above to reference whenever you perform a partial close.

 

Change the problem, use n small orders, simpler code and allows fine control

-BB-

 

I tried the code and it works perfectly.

Thank you very much to both for your help.

 
mesigual:

I tried the code and it works perfectly.

Thank you very much to both for your help.


If you are using more than one EA in an account this code might fail. I suggest to use BarrowBoy's solution. Partial close is a pain. Additionally with BB's solution you will be able to set TP and SL independently for each "part" of your order.

//z

Reason: