Wrong in calculation

To add comments, please log in or register
amando
791
amando  

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

Alain Verleyen
36041
Alain Verleyen  
Mind problem ;-)
amando
791
amando  
Alain Verleyen:
Mind problem ;-)

Can you eplain it a bit more?

Alain Verleyen
36041
Alain Verleyen  
amando:

Can you eplain it a bit more?

Please read the documentation before posting.

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
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...
amando
791
amando  
Alain Verleyen:

Please read the documentation before posting.

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

Alain Verleyen
36041
Alain Verleyen  
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.
whroeder1
17943
whroeder1  
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.
          Trade Functions / PositionSelect - Reference on algorithmic/automated trading language for MetaTrader 5

You only get one.
amando: sorry you are wrong,
You are wrong.
To add comments, please log in or register