Can´t get deal price

 

This is my code:

      double openPosition( double price ) {
         MqlTradeRequest mrequest = {0};
         MqlTradeResult mresult;
         
         mrequest.action = TRADE_ACTION_PENDING;
         mrequest.price = price;
         mrequest.symbol = _Symbol;
         mrequest.volume = this.lot;
         mrequest.magic = this.magic;
         mrequest.type = ORDER_TYPE_SELL_LIMIT;
         mrequest.type_filling = ORDER_FILLING_FOK;
         
         if( ! (OrderSend( mrequest, mresult ) && mresult.retcode == TRADE_RETCODE_DONE) ) {
            Print( "Failed to open position" );
            return 0.0;
         } else {
            return mresult.price; // Returns 0.0
         }
      }

Even OrderSend() returning true and MqlTradeResult.retcode is TRADE_RET_DONE, I can´t get the price at which the real was actually executed. In the logs I can see that the order was executed. I can also confirm the order was executed through the feedback in the graph. However, mresult.price insists returning 0.0.

Does anyone know what I´m missing here?

 
You are opening a pending order, there is no deal implied, so of course no deal price.
 
Alain Verleyen:
You are opening a pending order, there is no deal implied, so of course no deal price.

But eventually this order will be executed. In this case, is it possible to get the price at which the order was executed?
 

ENUM_POSITION_PROPERTY_DOUBLE

Identifier

Description

Type

POSITION_VOLUME

Position volume

double

POSITION_PRICE_OPEN

Position open price

double

POSITION_SL

Stop Loss level of opened position

double

POSITION_TP

Take Profit level of opened position

double

POSITION_PRICE_CURRENT

Current price of the position symbol

double

POSITION_SWAP

Cumulative swap

double

POSITION_PROFIT

Current profit

double


https://www.mql5.com/en/docs/trading/positiongetdouble

https://www.mql5.com/en/docs/trading

Documentation on MQL5: Trade Functions
Documentation on MQL5: Trade Functions
  • www.mql5.com
Trade Functions - Reference on algorithmic/automated trading language for MetaTrader 5
 
lorenooliveira:

But eventually this order will be executed. In this case, is it possible to get the price at which the order was executed?

Of course, but that happens later, not when the pending is send.

You need to check history for deal prices.

Reason: