How to detect orders state

 

Hi,

how can I detect (in mt4) if an order with ticket v_ticket is open or was closed by stoploss or takeprofit ?

Thanks a lot.

Alessandro

 
aleale72:

Hi,

how can I detect (in mt4) if an order with ticket v_ticket is open or was closed by stoploss or takeprofit ?

Thanks a lot.

Alessandro

Select the order in question and then check it's OrderCloseTime() if it's open it will return 0
 
RaptorUK:
Select the order in question and then check it's OrderCloseTime() if it's open it will return 0

RaptorUK:
Select the order in question and then check it's OrderCloseTime() if it's open it will return 0

and How to detect if it was closed for tp or sl ?

Thanks in advance.

 
aleale72:

and How to detect if it was closed for tp or sl ?

Thanks in advance.

Check it's OrderClosePrice() vs it's OrderStopLoss() and OrderTakeProfit()
 
RaptorUK:
Check it's OrderClosePrice() vs it's OrderStopLoss() and OrderTakeProfit()


But stoplosses and take profits can have slippage, right? Need to have a little leeway

Keep a record of every order you, or your EA closes. If you didn't close it then it must be one of these:

-Stoploss

-Takeprofit

-Stopout

I don't think there any other possibilities.

 
and it might be in closed trade you find in the OrderComment() [tp] or [sl]
 
  1. Some brokers modify comments with [tp] or [sl] other's don't. Don't depend.
  2. double distTP = MathAbs( OrderClosePrice() - OrderTakeProfit() ),
           distSL = MathAbs( OrderClosePrice() - OrderStopLoss() );
    bool ClosedBySL = distSL < distTP;

Reason: