Get Magic Number and Symbol from Open Position

 

I do not understand why this function do not give me back the magic number and the symbol of the position that is open


  long  magic;

  ulong  ticket;

  string symbol;

  ulong total=PositionsTotal();

  for(int i=total-1; i>=0; i--){

    ticket=PositionGetTicket(i);  

    PositionSelect(ticket);

    magic=PositionGetInteger(POSITION_MAGIC);  --------------> this give me back zero

    symbol=PositionGetString(POSITION_SYMBOL); ---------------> this give me back empty string

    }

    

Somebody can help me?

 
m.cadile:

PositionSelect(ticket);

 
   for(int i=PositionsTotal();i>=0;i--) //count backwards
     {
      ulong ticket=PositionGetTicket(i); //get the ticket

      if(PositionSelectByTicket(ticket)) // select the order
        {
                //carry on

        }
     }
https://www.mql5.com/en/docs/trading
Documentation on MQL5: Trade Functions
Documentation on MQL5: Trade Functions
  • www.mql5.com
An order is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels.A deal is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is...
 

now it's working,

thank you

 
m.cadile: I do not understand
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
          Messages Editor
Reason: