I need to help for magic number

 
Hello my friends, 
Please help me.
I can get magic number for one position.
If I have two position, how can i get the magic for second position?
For example:
I have a position buy for EUR-USD
I can get the magic number for this position with this order:

Positiongetinteger(POSITION_MAGIC)

ok?
Now I open the new sell position  for EUR_USD in the same symbol 
And same timeframe.
how can I get the magic number for sell position?

In fact. I want get the magic number for second position.
But I don't know that how do it
Thanks alot of you

 

You need to go through all positions in a loop. Example: loop through all positions and get the 'Magic' of each position.

[data folder]\MQL5\Experts\Examples\Moving Average\Moving Average.mq5

//+------------------------------------------------------------------+
//| Position select depending on netting or hedging                  |
//+------------------------------------------------------------------+
bool SelectPosition()
  {
   bool res=false;
//--- check position in Hedging mode
   if(ExtHedging)
     {
      uint total=PositionsTotal();
      for(uint i=0; i<total; i++)
        {
         string position_symbol=PositionGetSymbol(i);
         if(_Symbol==position_symbol && MA_MAGIC==PositionGetInteger(POSITION_MAGIC))
           {
            res=true;
            break;
           }
        }
     }
//--- check position in Netting mode
   else
     {
      if(!PositionSelect(_Symbol))
         return(false);
      else
         return(PositionGetInteger(POSITION_MAGIC)==MA_MAGIC); //---check Magic number
     }
//--- result for Hedging mode
   return(res);
  }
 
Vladimir Karputov #:

You need to go through all positions in a loop. Example: loop through all positions and get the 'Magic' of each position.

[data folder]\MQL5\Experts\Examples\Moving Average\Moving Average.mq5

Hello dear Vladimir.
Thank you from the bottom of my heart.
I tried hard and asked everyone, but no one answered.
Thanks alot for your answer