Ajuda CTrader.Buy() , OnTradeTransaction()

 

Hello guys

My question is regarding the return of the deal and order number in OnTradeTransaction() in HEDGE accounts

I'm using the CTrader library to perform operations

Well, let's go. In this example the Expert enters PURCHASED , I check the code return and present   it in the log as you can see below

   int trycath = 1 ;
   while ( true )
     {
       if (trycath == limitTryedSendOrder)
         break ;
       bool returnedTrade = trade.Buy(lots, _Symbol , 0 , stoploss, takeprofit,comment);
       ulong retCode = trade.ResultRetcode();
       if (!(retCode == TRADE_RETCODE_PLACED || retCode == TRADE_RETCODE_DONE ))
        {
         int errorCode = GetLastError ();
         Print ( "lots    " +lots+ "   BuyMarket : " +errorCode+ "         |        ResultRetcode :  " +retCode);
         ResetLastError ();
         trycath++;
         Sleep ( 150 );
        }
       else
        {
         order = trade.ResultOrder();
         deal = trade.ResultDeal();
         break ;
        }
     }
   Print ( "\n===== A MERDADO COMPRA | RESULT RET CODE :  " +trade.ResultRetcode());
   Print ( "LOTE ENVIADO  :  " +lots);
   Print ( "TKT DEAL : " +deal);
   Print ( "TKT OFERTA : " +order);



print log


Notice the deal order number returned in my log...

If we look at the log of OnTradeTransaction( ) , we will notice that curiously the number of Orders of Deals that is used as   references the order transaction in all its event steps, are different from those returned right after the order request ( trade.ResultOrder() and trade.ResultDeal()) .

The only thing that hits the OnTradeTransaction( ) logs is the magic number.

The number that OnTradeTransaction( ) returns me is:
Deals -1280893669

Order - 1280342342

Another curious fact is that the Order and Deals number is returning negatively.

Why does it happen ?

In Netting these problems never appeared for me!
can someone help me? Thank you all in advance.

Documentação sobre MQL5: Manipulação de eventos / OnTradeTransaction
Documentação sobre MQL5: Manipulação de eventos / OnTradeTransaction
  • www.mql5.com
OnTradeTransaction - Manipulação de eventos - Referência MQL5 - Referência sobre algorítimo/automatização de negociação na linguagem para MetaTrader 5
 
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Transaction===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the deal: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      position : 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the deal: DEAL_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Status of the order: ORDER_STATE_STARTED
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the order: ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Stop Loss: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Take Profit: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price that triggers the Stop Limit order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Trade symbol: 
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pending order expiration time: 1970.01.01 00:00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration type: ORDER_TIME_GTC
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the trade transaction: TRADE_TRANSACTION_REQUEST
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume in lots: 0.00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Request===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the trade operation: TRADE_ACTION_DEAL
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Comment to the order: 
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      position : 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Deviation from the requested price: 10
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration time: 1970.01.01 00:00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Magic number of the EA: 12345
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price: 0.99808
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Stop Loss level of the order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Take Profit level of the order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      StopLimit level of the order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Trade symbol: EURUSD
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the order: ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order execution type: ORDER_FILLING_FOK
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration type: ORDER_TIME_GTC
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume in lots: 0.71
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Result===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Code of the operation result: 10021
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the deal: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume of the deal: 0.00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price of the deal: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Bid: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ask: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Comment to the operation: 
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Request ID: 106
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pass : #1
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Request received: place a market order
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Transaction===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the deal: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      position : 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the deal: DEAL_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: -1280342342
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Status of the order: ORDER_STATE_STARTED
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the order: ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price: 0.99809
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Stop Loss: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Take Profit: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price that triggers the Stop Limit order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Trade symbol: EURUSD
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pending order expiration time: 1970.01.01 00:00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration type: ORDER_TIME_GTC
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the trade transaction: TRADE_TRANSACTION_ORDER_ADD
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume in lots: 0.71
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pass : #1
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Open a new market order: ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Transaction===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the deal: -1280893669
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      position : 50259265210
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the deal: DEAL_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: -1280342342
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Status of the order: ORDER_STATE_STARTED
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the order: ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price: 0.99809
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Stop Loss: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Take Profit: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price that triggers the Stop Limit order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Trade symbol: EURUSD
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pending order expiration time: 1970.01.01 00:00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration type: ORDER_TIME_GTC
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the trade transaction: TRADE_TRANSACTION_DEAL_ADD
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume in lots: 0.71
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pass : #1
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Deal added to history: #-1280893669, DEAL_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      EURUSD: new position opened
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ====== Abertura de uma ordem a mercado
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ==== RETORNO COMPRA
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      DEAL    -1280893669
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      order      -1280342342
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      lote    0.71
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Transaction===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the deal: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      position : 50259265210
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the deal: DEAL_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: -1280342342
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Status of the order: ORDER_STATE_FILLED
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the order: ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price: 0.99809
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Stop Loss: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Take Profit: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price that triggers the Stop Limit order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Trade symbol: EURUSD
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pending order expiration time: 1970.01.01 00:00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration type: ORDER_TIME_GTC
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the trade transaction: TRADE_TRANSACTION_ORDER_DELETE
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume in lots: 0.00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pass : #1
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Deleted from the list of open orders: #-1280342342, ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Transaction===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the deal: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      position : 50259265210
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the deal: DEAL_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: -1280342342
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Status of the order: ORDER_STATE_FILLED
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the order: ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price: 0.99809
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Stop Loss: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Take Profit: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price that triggers the Stop Limit order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Trade symbol: EURUSD
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pending order expiration time: 1970.01.01 00:00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration type: ORDER_TIME_GTC
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the trade transaction: TRADE_TRANSACTION_HISTORY_ADD
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume in lots: 0.00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pass : #1
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order added to the history: #-1280342342, ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Transaction===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the deal: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      position : 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the deal: DEAL_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Status of the order: ORDER_STATE_STARTED
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the order: ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Stop Loss: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Level of Take Profit: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price that triggers the Stop Limit order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Trade symbol: 
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pending order expiration time: 1970.01.01 00:00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration type: ORDER_TIME_GTC
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the trade transaction: TRADE_TRANSACTION_REQUEST
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume in lots: 0.00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Request===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the trade operation: TRADE_ACTION_DEAL
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Comment to the order: 
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      position : 0
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Deviation from the requested price: 10
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration time: 1970.01.01 00:00
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Magic number of the EA: 12345
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: -1280342342
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price: 0.99809
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Stop Loss level of the order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Take Profit level of the order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      StopLimit level of the order: 0.00000
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Trade symbol: EURUSD
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Type of the order: ORDER_TYPE_BUY
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order execution type: ORDER_FILLING_FOK
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Order expiration type: ORDER_TIME_GTC
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume in lots: 0.71
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      ---===Result===---
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Code of the operation result: 10009
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the deal: -1280893669
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ticket of the order: -1280342342
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Volume of the deal: 0.71
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Price of the deal: 0.99809
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Bid: 0.99809
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Ask: 0.99809
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Comment to the operation: 
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Request ID: 107
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Pass : #1
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      Request received: place a market order
CS      0       14:04:08.638    RDS_BOT(EURUSD,M1)      

 
You are posting in the English forum, so please write in English. Alternatively post in the Portuguese forum.
 

Trading forum, automated trading systems and trading strategies testing

Help CTrader.Buy() and OnTradeTransaction()

Vinicius de Oliveira , 10.28.2022 14:01



Good Morning!!


If you notice, the value of ResultOrder() matches the value of POSITION in OnTradeTransaction:


Wouldn't this information be enough to meet your expectations there?


. . .