Download MetaTrader 5

Obtain the price of an open position

To add comments, please log in or register
Publish your application in the Market - 7 million potential clients will see it
Eagle44
17
Eagle44 2016.03.08 23:25 

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 

Eagle44
17
Eagle44 2016.03.08 23:46  
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);
         }

   
   }   
Alain Verleyen
Moderator
30739
Alain Verleyen 2016.03.09 14:11  

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

Eagle44
17
Eagle44 2016.03.10 01:20  

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 

Alain Verleyen
Moderator
30739
Alain Verleyen 2016.03.10 08:56  
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.

To add comments, please log in or register