How to inform EA if an order is closed by hitting stop loss or take profit?

 

Dear all

If I want to open another order immediately when an order is closed automatically by hitting stop loss or take profit, how to write it? (if the original order is closed manually, I know how to write it, but have no idea if it is closed automatically)

Pls help!

Wing

 

Look at OrderSelect(), MODE_HISTORY, OrderStopLoss(), OrderTakeProfit(), and OrderClosePrice()

 

if (counted_orders != OrdersTotal())

{

check orders.....;

counted_orders = OrdersTotal();

}

 

So......it means I have to check for any order closed in last tick, right?

However, I don't understand, what's the reason I have to check OrderStopLoss(), OrderTakeProfit(), and OrderClosePrice() ?

How can I find out the order was closed automatically by checking those three parameters?

Wing

 
If OrederClosePrice() == OrderTakeProfit() then it's a good chance that the order closed automatically when it hit it's TP, same for SL
 

???

OrederClosePrice() is a close "price" but OrderTakeProfit() is a profit "value", how can they be compared???

 
wing:

???

OrederClosePrice() is a close "price" but OrderTakeProfit() is a profit "value", how can they be compared???

No it isn't . . . it returns the TP price, not the profit . https://docs.mql4.com/trading/OrderTakeProfit Returns take profit value for the currently selected order. https://docs.mql4.com/trading/OrderStopLoss Returns stop loss value for the currently selected order.

Maybe you are thinking of . . https://docs.mql4.com/trading/OrderProfit Returns the net profit value (without swaps or commissions) for the selected order. For open positions, it is the current unrealized profit. For closed orders, it is the fixed profit.

Reason: