Download MetaTrader 5

PositionSelectbyTicket Problem

To add comments, please log in or register
Somsri Sarkar
2943
Somsri Sarkar  

Hi,

I have this following code which is not selecting any open position. control is not going inside the "Do something" area.

 int total=PositionsTotal();
   int count=0;
   for (int cnt=0; cnt<=total-1; cnt++) 
      {     
         count++;
         ulong ticket=PositionGetTicket(count);
         if(PositionSelectByTicket(ticket))
          {

            //Do something

           }

         }

 Please help

Thank you in advance. 

Nguyen Nga
9715
Nguyen Nga  

to use PositionSelectByTicket, you must know ticket number.

your code above is wrong, so ticket  = 0.

 

 int total=PositionsTotal();
   int count=0;
   for (int cnt=0; cnt<=total-1; cnt++) 
      {     
         //count++;
         ulong ticket=PositionGetTicket(count);
         if(PositionSelectByTicket(ticket))
          {

            //Do something

           }

         }
Somsri Sarkar
2943
Somsri Sarkar  
Nguyen Nga:

to use PositionSelectByTicket, you must know ticket number.

your code above is wrong, so ticket  = 0.

 

Yes that's why I used PositionGetTicket & count is the position number.

It it doesn't works in that way, then how should do it? I need to select opened orders.

Nguyen Nga
9715
Nguyen Nga  
Below is  code. Delete "count++"
int total=PositionsTotal();
   int count=0;
   for (int cnt=0; cnt<=total-1; cnt++) 
      {     
         //count++;
         ulong ticket=PositionGetTicket(count);
         if(PositionSelectByTicket(ticket))
          {

            //Do something

           }

         }
Somsri Sarkar
2943
Somsri Sarkar  
Nguyen Nga:
Below is  code. Delete "count++"

Hi Thank you its working now.

To add comments, please log in or register