Array Out of Range (Trying to use ArrayFill to get initial volume of a ticket)

 

Hi I'm trying to get the initial volume of a ticket, so I can then use that value in my EA.




Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of...
 
  1. Don't post pictures of code, they are too hard to read.

    Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor


  2. If there are n positions, their indexes are [0…n-1]. Not n+1!
 
int Initial_Volume()
   {
    int IV;    
    int total = PositionsTotal();
    for(int i = total-1; i >= 0; i--)
      {
       if(PositionGetTicket(i) <= 0) continue;
       if(PositionGetInteger(POSITION_MAGIC) != MagicNumber || PositionGetString(POSITION_SYMBOL) != Symbol()) continue;
       double IVA[];
       int PV = PositionGetDouble(POSITION_VOLUME);
       ArrayFill(IVA,0,123,PV);
       IV = ArrayMaximum(IVA,0,123);              
      }   
    return IV;   
   } 
 
William Roeder:
  1. Don't post pictures of code, they are too hard to read.

    Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor


  2. If there are n positions, their indexes are [0…n-1]. Not n+1!

thanks for the reply, i had it at -1 and it still did not work. ill give it a go with 0

 
still does not work with it set to 0
 
Nagisa Unada:

I think you probably want it this way.

thanks for the reply/help

the code you posted runs without errors, but im looking for a way to get the max volume of the current trade ticket. 

this code returns something different 

so do we have to make a new array each trade?

 
There was an error in my program and I removed it.
 
Nagisa Unada:
There was an error in my program and I removed it.

right as i posted my last comment i noticed it disappeared.. i thought i did something wrong when i was replying lol

 

How about this one?

int Initial_Volume()
{
   int IV;
   int total = PositionsTotal();
   double IVA[];
   ArrayResize(IVA, total);

   for(int i = 0; i < total; i++)
   {
      if(PositionGetTicket(i) <= 0) continue;
      if(PositionGetInteger(POSITION_MAGIC) != MagicNumber || PositionGetString(POSITION_SYMBOL) != Symbol()) continue;
      IVA[i] = PositionGetDouble(POSITION_VOLUME);
   }

   IV = (int)IVA[ArrayMaximum(IVA)];
   return (IV);
} 
 
Nagisa Unada:

How about this one?

it wont compile 3 errors and 1 warning