ResultDeal() yields wrong ticketnr.

 

 Hey Guys,


I want to get the ticketnr. after I opened a position to be able to work with it (close it) later.




 if(instruction == OpenLong)

     {
      double entry = SymbolInfoDouble(Symbol(), SYMBOL_ASK); 
      if(trading.Buy(EAVolume, Symbol(), entry, 0.0, 0.0, "EA"))
        {
         if(trading.ResultRetcode())
           {
            if(trading.ResultDeal())
              {
               openPosition = true;
               instruction = DoNothing;
               openPositionType = typeLong;
               openPositionTicket = trading.ResultDeal();
               PrintFormat("Long position %i successfully opened. RetCode: %i", openPositionTicket, trading.ResultRetcode());
              }
            else
              {
               PrintFormat("unable to open long position (third step)");
              }
           }
         else
           {
            PrintFormat("unable to open long position (RetCode: %i)", trading.ResultRetcode());
           }
        }
      else
        {
         PrintFormat("unable to open long position (first step)");
        }
     }
 


however, I get a ticket nr. thats a litte lower that what the actual nr. is.


Any Ideas?


Regards

Lucas

 

Check out the algorithm:

Forum on trading, automated trading systems and testing trading strategies

How to start with MQL5

Vladimir Karputov, 2020.10.22 20:31

We catch the transaction

Code: We catch the transaction.mq5

We catch the transaction


This is a blank - an example of how to control a trading signal. This code avoids the situation: opening multiple positions. How it works: after a trade order is generated, we increase the 'SPosition' structure. In OnTick, if 'SPosition' is greater than zero, go to the block for opening positions. In OnTradeTransaction, we monitor the situation when a position appears exactly on our signal.


Example:

2021.01.08 15:28:08.316 We catch the transaction (USDJPY,M30)   We catch the transaction.mq5 SearchTradingSignals, OK: Signal BUY
2021.01.08 15:28:08.529 We catch the transaction (USDJPY,M30)   We catch the transaction.mq5 PrintResultTrade, Symbol: USDJPY, Code of request result: 10009, Code of request result as a string: done at 103.907Trade execution mode: Trading on live streaming prices
2021.01.08 15:28:08.529 We catch the transaction (USDJPY,M30)   Deal ticket: 804407087, Order ticket: 823201677, Order retcode external: 0, Volume of deal or order: 1.00
2021.01.08 15:28:08.529 We catch the transaction (USDJPY,M30)   Price, confirmed by broker: 103.907, Current bid price: 103.907 (the requote): 103.907, Current ask price: 103.907 (the requote): 103.907


Tab 'Trade':


Reason: