PositionGetTicket failed to get second ticket position

 

Hi,

I created a TrailingStop ea to help to modify stop loss position. After that, my data provider is OANDA, the first position I opened is USDJPY.sml and second position is AUDJPY. However, when I run this ea with the code below, it fails to return second position AUDJPY, for both index 0 and 1, it still returns USDJPY.sml as the symbol, although ulong posTicket does return 2 numbers.


   for(int i = PositionsTotal()-1; i >= 0; i--){
      ulong posTicket = PositionGetTicket(i);

      Print("i: ",i," get ticket: ",PositionGetTicket(i)," Symbol: ",PositionGetSymbol(POSITION_SYMBOL));
      if(PositionSelectByTicket(posTicket)){
         if(PositionGetSymbol(POSITION_SYMBOL) != _Symbol) continue;
         posPriceOpen = PositionGetDouble(POSITION_PRICE_OPEN);
         double posTp = PositionGetDouble(POSITION_TP);
         double posSl = PositionGetDouble(POSITION_SL);
                       
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY){
            buyPos = posTicket;
            ..................
            .................

I printed the comment and get result like:

i:1 get ticket: 11594375 Symbol: USDJPY.sml

i:0 get ticket: 11591608 Symbol: USDJPY.sml


Initially I thought the Avatrade mt5 got hidden bug, so I downloaded the official mt5 but still got the same problem.

So, it failed to return symbol AUDJPY. May someone advise me on this? Thank you.

 
lateboomer:

Hi,

I created a TrailingStop ea to help to modify stop loss position. After that, my data provider is OANDA, the first position I opened is USDJPY.sml and second position is AUDJPY. However, when I run this ea with the code below, it fails to return second position AUDJPY, for both index 0 and 1, it still returns USDJPY.sml as the symbol, although ulong posTicket does return 2 numbers.


I printed the comment and get result like:

i:1 get ticket: 11594375 Symbol: USDJPY.sml

i:0 get ticket: 11591608 Symbol: USDJPY.sml


Initially I thought the Avatrade mt5 got hidden bug, so I downloaded the official mt5 but still got the same problem.

So, it failed to return symbol AUDJPY. May someone advise me on this? Thank you.

I have found out the issue. The problem is with 

PositionGetSymbol(POSITION_SYMBOL)

instead it should be 

PositionGetSymbol(i)


I am newbie in mql5 programming, so I followed a Youtuber to write the code. So the problem is solved.