Find open order of Stop Loss or Take Profit

 

Guys is there any way to get whole history of one trade. I mean for simple trade we open trade (Ex: Send Buy order) and we close that trade (Ex: Stop Loss hit). I can catch when stop loss is hit in OnTradeTransaction. Can I find related Buy order of that stop loss?

For example in the below History table, Deal 2 is shorting. So we started trade. And in Deal 8 Stop loss was hit for Deal 2. As I said I can catch Deal 8 in  OnTradeTransaction. Is there a way to find which Deal started this operation. Deal 2 or 3 ?

 

Perhaps this code will help:

Example: catching a Take Profit trigger

How to start with MQL5
How to start with MQL5
  • 2020.09.17
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
Vladimir Karputov:

Perhaps this code will help:

Example: catching a Take Profit trigger

Thanks for reply Vladimir. I can catch Take Profit or Stop Loss triggers.It is a little bit different that the code you shared but I still can catch.But in that example code gets informations like volume,price and etc. for the take profit deal. But I wanna acces to information about buy deal it self.

My ultimate aim is: 
 trade.PositionOpen(Symbol(), orderType, InpOrderSize, openPrice, stopLossPrice, takeProfitPrice, "AAA");

As you can see I pass comment to PositionOpen. I want to catch that comment when I catch Take Profit or Stop Loss. For some reason (probably broker is doing that) comments for Stop Loss becomes : sl0.9221 But I wanna see same comment in SL and TP too. If I cant change SL or TP comments would be nice to access Open deal comment

Reason: