function () which returns true if the position is closed by the TP or Sl

 

Hello ,


I would like to know if a function that returns true if the postion (select by ticket) reached the TP or SP exists ?

Or check if the position is closed by a reverse transaction.



I have researched in the documentation and the forums but I don't know how.


Sorry, if there are grammar mistakes because I speak French and I use the translation.

 
You can always catch a transaction in the Expert Advisor in 'OnTradeTransaction' and determine that this transaction occurred as a result of Stop Loss or Take Profit triggering.
 
Derek Dati: I would like to know if a function that returns true if the postion (select by ticket) reached the TP or SP exists ?

Yes: bool closedByTPorSL(int position){ return positionClosed(position); }
     How To Ask Questions The Smart Way. 2004
          Be precise and informative about your problem

 

On Mql4 it was easy, we just had to compare if orderpriceclose() == ordertakeprofit()


On mql5 there is no corresponding function



I tried with ordergetdouble (ORDER_TP) but it returns 0

if someone could give or write me a simple code to check if my order hit the TP


and at the same time simply explain to me the difference between Order, Deal, Position

 
and thank you for this interesting article @William Roeder !
 
Derek Dati: On Mql4 it was easy, we just had to compare if orderpriceclose() == ordertakeprofit()
  1. That will not work! Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

    And There can be slippage.

  2. Best you can do is bool isByTP = MathAbs(OrderClosePrice() - OrderTakeProfit()) < MathAbs(OrderClosePrice() - OrderStopLoss());