Download MetaTrader 5
To add comments, please log in or register
Interested in Signals activity? Come and track!
nicolasxu 2015.02.26 18:26 
void updatePosition(const MqlTradeTransaction& trans, double& iPosition)  {
   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
Alain Verleyen 2015.02.26 23:38  

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