# Wrong in calculation

3774

Hello,

i Use MT5 with Hedging mode and i want to know, the last open position volume

```double lastLot(const string sym,const int magic)  //aller offenen Positionenauf diesem Symbol und dieser MN
{
double LastLot=0;
if(PositionsTotal()>0)
{
for(int i=0; i<PositionsTotal(); i++)
{

if(PositionGetString(POSITION_SYMBOL)== sym &&
PositionGetInteger(POSITION_MAGIC)== magic
)
{
LastLot=0;
LastLot=PositionGetDouble(POSITION_VOLUME);
}
}
}
Print(LastLot);
return(LastLot);
}```

this works fine, as long i have only 1 open position

as soon i have 2 open position, it will be used the Volume for Position 1 and Position 2

LastLot = Volume1 + Volume2

i geht the last ticket number in the same way, so is this an bug from MT5 or does i have a mind problem

amando

42172

Mind problem ;-)
3774

Alain Verleyen:
Mind problem ;-)

Can you eplain it a bit more?

42172

amando:

Can you eplain it a bit more?

To ensure receipt of fresh data about a position, it is recommended to call PositionSelect() right before referring to them.

Documentation on MQL5: Trade Functions / PositionGetString
• www.mql5.com
The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. The position property should be of the string type. There are 2 variants of the function. 2...
3774

Alain Verleyen:

sorry you are wrong,

```double lastLot(const string sym,const int magic) //aller offenen Positionenauf diesem Symbol und dieser MN
{
double LastLot=0;
if(PositionsTotal()>0)
{
for(int i=0; i<PositionsTotal(); i++)
{
PositionSelect(_Symbol);
if(PositionGetString(POSITION_SYMBOL)== sym &&
PositionGetInteger(POSITION_MAGIC)== magic
)
{
LastLot=0;
LastLot=PositionGetDouble(POSITION_VOLUME);
}
}
}
Print(LastLot);
return(LastLot);
}```

even with position select MT5 calculate wrong

42172

amando:

sorry you are wrong,

even with position select MT5 calculate wrong

Ok, for sure it's certainly MT5 or Metaquotes, or some cosmic ray or my fault, certainly not yours.
25313

amando: i geht the last ticket number in the same way, so is this an bug from MT5 or does i have a mind problem

You have the "mind problem." Perhaps you should read the manual.

For the "netting" interpretation of positions only one position can exist for a symbol at any moment of time.

If individual positions are allowed ... In this case, PositionSelect will select a position with the lowest ticket.