How to check if an order has been closed for stop loss - page 2

 

Could you please only answer if you know what you are talking about ?

This is a topic about MT5/mql5, I will remove all irrelevant posts.

There is no stoploss price in history on MT5.

 

The main problem in mql5 (hedging account) is to know the Stop Loss price, when a position is closed, due to lack of positions history. You can use HistorySelectByPosition() to find your initial Stop Loss (Stop Loss of the initial order), but if you have modified that Stop Loss later, it generates new orders to do it, without the same POSITION_ID, and therefore, they will not be selected by HistorySelectByPosition() function, so it becomes very difficult to know the last Stop Loss you placed.

I don't know if it can be considered as a bug, but if not, it should be.

Regards.

Documentation on MQL5: Trade Functions / HistorySelectByPosition
Documentation on MQL5: Trade Functions / HistorySelectByPosition
  • www.mql5.com
Trade Functions / HistorySelectByPosition - Reference on algorithmic/automated trading language for MetaTrader 5
 
Jose Francisco Casado Fernandez:

The main problem in mql5 (hedging account) is to know the Stop Loss price, when a position is closed, due to lack of positions history. You can use HistorySelectByPosition() to find your initial Stop Loss (Stop Loss of the initial order)...

No you can't or I misunderstood you.

Current Stoploss is nowhere in history.

 
Alain Verleyen:

No you can't or I misunderstood you.

Stoploss is nowhere in history.

You can use HistorySelectByPosition(), with your POSITION_ID, and then you can find the first order with that POSITION_ID, and check the Stop Loss of this order (HistoryOrderGetDouble(ticket, ORDER_SL). It worked for me, but
.the problem is when you modify that Stop Loss later.
 
Jose Francisco Casado Fernandez:
You can use HistorySelectByPosition(), with your POSITION_ID, and then you can find the first order with that POSITION_ID, and check the Stop Loss of this order (HistoryOrderGetDouble(ticket, ORDER_SL). It worked for me, but
.the problem is when you modify that Stop Loss later.

Ok understood now, you are right.

 
Jose Francisco Casado Fernandez:
You can use HistorySelectByPosition(), with your POSITION_ID, and then you can find the first order with that POSITION_ID, and check the Stop Loss of this order (HistoryOrderGetDouble(ticket, ORDER_SL). It worked for me, but
.the problem is when you modify that Stop Loss later.
And then, check ORDER_POSITION_ID equal to DEAL_POSITION_ID,
then check DEAL_ENTRY, if OUT, get HystoryDealGetDouble(ticket,DEAL_PRICE).

If DEAL_PRICE equal to HistoryOrderGetDouble(ticket,ORDER_SL), then it means that the Order has been close due to stop loss.

Here's my opninion.

 
Alain Verleyen:

Ok understood now, you are right.

Ok, and do you know why if you modify the Stop Loss later, the new order generated to do it, doesn't show the same POSITION_ID???. It would the perfect solution for this matter. Is it a bug???. Thanks.
 
Roberto Jacobs:

If DEAL_PRICE equal to HistoryOrderGetDouble(ticket,ORDER_SL), then it means that the Order has been close due to stop loss.

What about slippage?
 
Roberto Jacobs:
And then, check ORDER_POSITION_ID equal to DEAL_POSITION_ID,
then check DEAL_ENTRY, if OUT, get HystoryDealGetDouble(ticket,DEAL_PRICE).

If DEAL_PRICE equal to HistoryOrderGetDouble(ticket,ORDER_SL), then it means that the Order has been close due to stop loss.

Here's my opninion.

Yes, it's what I was saying. I did it so, and it worked, but if you modify the initial Stop Loss, it generates a new order WITHOUT the same POSITION_ID. I don't know why. I think, it is a bug. Regards,.
 
honest_knave:
What about slippage?

No need to look slippage, because the order has been close, and close price is on HystoryDealGetDouble(ticket, DEAL_PRICE).
If the order has not been in close, and you make an order to close, then you should consider how much slip, so that no error requotes.