Obtain the price of an open position

 

How can I obtain the price of an open position? I'm gonna use this price to specify the StopLoss and TakeProfit.

 I've traied PositionGetDouble(POSITION_PRICE_OPEN) but it's not working.

Thanks 

 
Vasyl Nosal:
Code in mql4

I'm using mql5 

 

 if(last_tick.last<iMA_buf[0])
   {
      if(last_tick.last<(iMA_buf[0]-1) && last_tick.last> (iMA_buf[0]-2))
        if(m_Position.Select(my_symbol))
            Print("Short Position!!");
        else
        {
            if(m_Position.PositionType()==POSITION_TYPE_SELL)
               if(PositionGetDouble(POSITION_VOLUME)< Volume)
                  m_Trade.Sell(1,my_symbol);
                  Open_Price=PositionGetDouble(POSITION_PRICE_OPEN);
                  Print(Open_Price);
                  m_Trade.PositionOpen(my_symbol,ORDER_TYPE_SELL,1,last_tick.ask,Open_Price+StopLoss,Open_Price-StopGain);
         }

   
   }   
 

"Not working", what that means exactly ? why are you checking position type, volume or open price when Position.Select() is false ?

 

What I'm trying to do is after the Sell position is open m_Trade.Sell(1,my_symbol) I'm gonna set the StopLoss and TakeProfit based on the Price that I've openned. To do this I'm trying to use the code:  m_Trade.PositionOpen(my_symbol,ORDER_TYPE_SELL,1,last_tick.ask,Open_Price+1,Open_Price-5). MetaTrader5 says that sl=1 and tp=-5 are invalid. It seens that Open_Price is "0".

So, how can I get obtain the price of an open position?

 

Thanks 

 
Eagle44:

What I'm trying to do is after the Sell position is open m_Trade.Sell(1,my_symbol) I'm gonna set the StopLoss and TakeProfit based on the Price that I've openned. To do this I'm trying to use the code:  m_Trade.PositionOpen(my_symbol,ORDER_TYPE_SELL,1,last_tick.ask,Open_Price+1,Open_Price-5). MetaTrader5 says that sl=1 and tp=-5 are invalid. It seens that Open_Price is "0".

So, how can I get obtain the price of an open position?

 

Thanks 

If position.Select() is false, that means there is no position.

Your code to set sl/tp must in the true case, not false.