How to get open price for transaction with DEAL_REASON_TP

 

Hello,

I've started programming in MQL5 (as hobby so far), once in college and in my first job I programmed heavily in C ++, but it was over 20 years ago :)

I have such a issue, probably I have no enough knowledge at yet.

After the setup occurs, I place three orders, which let's assume they triggered:

1. Position with SL1 and TP1

2. Position with SL1 and TP2

3. Position with SL1 and without TP (dynamic)

(same SL and three TPs)


After the orders are triggered and the first position on TP1 is closed, I would like to switch SL1 for the remaining positions to the launch price of Position 1.

And I don't have idea how to get "launch" price for Position 1. Here is my code:


   void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result)
     {
      if(HistoryDealSelect(trans.deal) == true)
        {
         ENUM_DEAL_REASON dealReason=(ENUM_DEAL_REASON) HistoryDealGetInteger(trans.deal,DEAL_REASON);
         if(dealReason == DEAL_REASON_TP)
           {
            OrderSelect(trans.order);
            //Get the open price for order which triggered position (???)
            double transactionOrderPriceOpen = (double)OrderGetDouble(ORDER_PRICE_OPEN);
            int positionTotal = PositionsTotal() - 1;
            //check open position and if are "connected" then change SL
            for(int i=0; i<=positionTotal; i++)
              {
               ulong ticket=PositionGetTicket(i);
               PositionSelectByTicket(ticket);
               if(ticket == (trans.position + 1) || ticket == (trans.position + 2))
                 {
                  double SL = PositionGetDouble(POSITION_SL);
                  double TP = PositionGetDouble(POSITION_TP);
                  Trade.PositionModify(ticket, transactionOrderPriceOpen, TP);
                 }
              }
           }
        }
     }


... and "transactionOrderPriceOpen" is 0.0 value always. 


I checked all the fields in the Transaction Object: https://www.mql5.com/en/docs/constants/structures/mqltradetransaction and any field gives the opening price of the position, I combine with the the Order for particular Transaction but also returns zero, in Deal connected to Transaction I do not see the "Price" field


I am asking for hints, thank you in advance for the guidance.

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Transaction Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Transaction Structure
  • www.mql5.com
For example, when sending a market buy order, it is handled, an appropriate buy order is created for the account, the order is then executed and removed from the list of the open ones, then it is added to the orders history, an appropriate deal is added to the history and a new position is created. All these actions are trade transactions...
Reason: