problem understanding PositionGetDouble(POSITION_VOLUME) and Volume()

 

I want to get the current volume of an open position but am obviously not doing it properly can do this in MT4 but lost on MT5. I have tried PositionGetDouble(POSITION_VOLUME) but this never changes from the original order even after increasing or decreasing the position. I also have tried putting Volume() which just gives a function not declared error. I have seen that I am supposed to select the ticket number first by either select by ticket or select by index. I do not understand how to do this.

Select by ticket is

bool Select(const string  symbol  // symbol) so I assume the string is a currency pair and the function returns just true or false and not the ticket number.

Select by index is

bool  SelectByIndex(int  index   // position index) which also appears to return true or false but the index part suggests a "for" loop which I do not understand what the indexed bit contains. (that is [i] contains what???)

Probably stupid again but confused

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Documentation on MQL5
 
BigAl:

I want to get the current volume of an open position but am obviously not doing it properly can do this in MT4 but lost on MT5. I have tried PositionGetDouble(POSITION_VOLUME) but this never changes from the original order even after increasing or decreasing the position. I also have tried putting Volume() which just gives a function not declared error. I have seen that I am supposed to select the ticket number first by either select by ticket or select by index. I do not understand how to do this.

Select by ticket is

bool Select(const string  symbol  // symbol) so I assume the string is a currency pair and the function returns just true or false and not the ticket number.

Select by index is

bool  SelectByIndex(int  index   // position index) which also appears to return true or false but the index part suggests a "for" loop which I do not understand what the indexed bit contains. (that is [i] contains what???)

Probably stupid again but confused

Please don't double post if it is still related to your other topic https://www.mql5.com/en/forum/8935. Please continue from that old topic coz you risking this topic gets deleted.
Value of a position
Value of a position
  • www.mql5.com
As each currency pair can only have one position is there a command/function to obtain the $value (assuming the base currency is USD) of that position or do I have to calculate it for myself?
 
phi.nuts:
Please don't double post if it is still related to your other topic https://www.mql5.com/en/forum/8935. Please continue from that old topic coz you risking this topic gets deleted.
This is not related to my other post. On MT4 forum I could close off a post but there does not seem to be a way of closing off previous posts. I have solved my previous problem thanks and this something different
 

Hi phi_nuts

sorry if I have confused things. This post was more to do with selecting a ticket than the volume stuff. maybe the volume bit should be on my previous post. what do you want me to do?


 
BigAl:

Hi phi_nuts

sorry if I have confused things. This post was more to do with selecting a ticket than the volume stuff. maybe the volume bit should be on my previous post. what do you want me to do?


Al right,

I'm a little "don't get it" with your question. If you can do this on MT4, can you show the mql4 code ?

 

I am afraid I cant do that due to confidentiality concerns but will try to explain better without breaking it.

Lets say I have a position open one lot of eurusd that has certain value. if the price changes so does the value of the position. If the value increases I want to take some profit so I will have to sell part of that position. To do that I need to calculate the amount of lots or part lots to sell based on the increase in value.

Problem 1 - After that has happened if I want to get the new volumes I have to either track the lot sizes or just get them from the server by using Volume() or GetPostionDouble(POSITION_VOLUME). When I try Volume() I get the message "function not declared", If I use GetPostionDouble(POSITION_VOLUME) I get the volume from the initial order and it does not update.

Problem 2 - I assume that I have to select the position first but the select by ticket and select by index are boolean and cant return a ticket number as in MT4.

I assume that to select by ticket I use Select(_Symbol) or SelectByIndex(index)

But neither is a ticket number - so how do I get the updated volume please

hopefully that makes it clearer for you
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Documentation on MQL5
 

Hi,

all you need to get the volume of a certain position are two steps.

#1. You select a position on a given symbol using PositionSelect(Symbol()); You are right, it returns boolean, but it does the job.

#2. After you select your position you use PositionGetDouble(POSITION_VOLUME); that's it.

Documentation on MQL5: Trade Functions / PositionGetDouble
Documentation on MQL5: Trade Functions / PositionGetDouble
  • www.mql5.com
Trade Functions / PositionGetDouble - Documentation on MQL5
 

That easy!!!

Thanks to Wahoo and phi_nuts

 

Final question I hope. So why do we have so many ways of doing the same thing in the "Documentation" as below? Am I missing something really basic here:


PositionSelect(Symbol()

as well as

Select(_Symbol)

and

PositionGetDouble(POSITION_VOLUME)

as well as

double  Volume() const gets the volume of the position (using select methods)

double  Volume() const gets the volume of the deal (using select methods) or is this the volume when a position is first opened

double  Volume() const gets the value of the last deal (using name method) or is this what it says the volume of the last deal

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
Reason: