Download MetaTrader 5

PositionSelect() failed with error code: 4753 on 1999.06.09 EURUSD

To add comments, please log in or register
nicolasxu
304
nicolasxu  
void updatePosition(const MqlTradeTransaction& trans, double& iPosition)  {
   printTradeTransaction(trans);
   if(trans.type == TRADE_TRANSACTION_HISTORY_ADD) {
      printf("TRADE_TRANSACTION_HISTORY_ADD detected");
      printf("PositionSelect(Symbol()) result: %d ",PositionSelect("EURUSD") );
      printf("Symbol() is: %s", Symbol());
      if(PositionSelect(Symbol())) { // it some failes, why??
        
        printf("PositionSelect() success");
        
        double symbolPosition = PositionGetDouble(POSITION_VOLUME);
        
        
        
        long pType = PositionGetInteger(POSITION_TYPE);
        
        if(pType == POSITION_TYPE_BUY) {
        
            symbolPosition = symbolPosition;   
            
        } else {
        
            symbolPosition = -symbolPosition;
        }
        
        iPosition = symbolPosition;
        printf("position updated to: %f", iPosition);
        
      }  else {
         int errorCode = GetLastError();
         printf("PositionSelect() error: %d", errorCode);
      }
   }
}

I use above code to get the position in OnTradeTransaction() handler. Most of the time, it works well. But I PositionSelect(Symbol()) always fails on 1999.06.09 EURUSD data during the test. The error code is: 4753, and I can't find any explanation. 

 

Can you please tell me why PositionSelect() fails? Thanks!

Alain Verleyen
Moderator
33339
Alain Verleyen  

So that means you don't have a position on this symbol at this moment.

This code is run when the EA receive an event that an order had been added to history, which doesn't mean you should have a position. What is the problem ?

To add comments, please log in or register