PositionSelectbyTicket Problem

 

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. 

 

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

           }

         }
 
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.

 
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

           }

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

Hi Thank you its working now.

Reason: