Get Magic Number and Symbol from Open Position

To add comments, please log in or register
m.cadile
15
m.cadile  

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?

fxsaber
13560
fxsaber  
m.cadile:

PositionSelect(ticket);

Alois Mwirichia
180
Alois Mwirichia  
   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...
m.cadile
15
m.cadile  

now it's working,

thank you

William Roeder
19170
William Roeder  
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
To add comments, please log in or register