What happens when a pending order is placed

 

I want to place a pending long order and then when "something" happens :

a. delete it OR

b. if it is executed, close it.

Will it change type if in the meanwhile the price hits the buy limit or will another order be created and this one will be automatically closed?

If another order is created, how can I close it,since I won't know it's ticket number?

Cheers

 

1. There is no "pending long order" - it is either Buy-Stop or Buy-Limit. So please be clear in your question.

2. What is "someting" ?

3. If a pending order is executed, which, in your case, means that ask price came to its level and order has opened, it will become an open order and change its type.

4. If before that some other stop or limit order is executed, if any open order is closed, or whatever else (except p.3 above) the order will be sitting there with the initial ticket number it had.

5. It will not automatically close. To remove it you have to code the procedure and the conditons of order removal.

Your question is very unclear. I had to guess what you were asking, but I hope I was able to address some of your concerns.

 

I should be more specific:

-It's a buy_limit. I don't specify the SL or TP. I store it's ticket number so I can close/detele it when I want to.

-"something" is a condition I check at every tick. It could be for example : High[1] > iMA(...)

-at that point I want to delete the order if it's still "op_buylimit" or close it if it's "op_buy".

-What I am asking is whether the ticket number I have stored could be used to perform both the two functions above.

*EDIT:also, what will OrderDelete() return if you try to apply to an "op_buy" order?

 
The ticket number of your stop/limit order is the same after the order goes from being stop/limit to "op_buy/op_sell" type. But before you use the stored ticket number to perform the action called for by that "something" happening, you should check the order type of the order searching by ticket number. If the type is <2 (i.e. "op_buy" or "op_sell") use OrderClose(). If the type is still >2 (any pending order) then use OrderDelete(). Using both is not a good way to go since one of them will give you and error.
 

Thanks ! Do you know what happens to the trade when it closes? Does it become unreachable with a ticketNumer?

 
50094689:

Thanks ! Do you know what happens to the trade when it closes? Does it become unreachable with a ticketNumer?

No, you can still select it with the ticket number, it just moves to the History Pool.
 
50094689:

Thanks ! Do you know what happens to the trade when it closes? Does it become unreachable with a ticketNumer?


if the trade is pending or open use

OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);

if the order has closed you need to use:

OrderSelect(ticket,SELECT_BY_TICKET,MODE_HISTORY);

I'm working on an EA with pending orders right now and I'm using this code:

   if(!OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
      {
      int error=GetLastError();
      Print("failed selecting ",ticket,". checking if already closed... ",error);
      if(!OrderSelect(ticket,SELECT_BY_TICKET,MODE_HISTORY))
         {
         error = GetLastError();
         Print("failed selecting again. no idea whats wrong: ",error);
         }
      }

because before selecting, I'm not sure which type it will be. It tries TRADES, and if that fails, it tries HISTORY

 
alladir:


if the trade is pending or open use

if the order has closed you need to use:

Not if selecting by ticket, there is no need to specify the pool . . . the ticket number is unique.
 
RaptorUK:
Not if selecting by ticket, there is no need to specify the pool . . . the ticket number is unique.


ah great thanks!

Ok, ignore my code

 
thanks!
 
50094689:

*EDIT:also, what will OrderDelete() return if you try to apply to an "op_buy" order?


For this kind of question, you can find the answer in Metaeditor. Click on OrderDelete in your mq4 file and press F1, you will see:

bool OrderDelete(

int ticket, color Color=CLR_NONE)

Deletes previously opened pending order. If the function succeeds, the return value is true. If the function fails, the return value is false. To get the detailed error information, call GetLastError().

(this is what I should have done with OrderSelect :-S )

So that tells you OrderDelete is returns a boolean variable (true/false) and returns false if it didn't work (e.g. if the order isn't a pending order).

Reason: