OnTradeTransaction(): no Magic number, no comment, and & either-or symbols?

 

Hi,

am I doing something wrong?

  1. To know where the calls of OnTradeTransaction() belong to I would like to use the magic number. The only (why only?) type that provides the magic number is request - BUT in OnTradeTransaction() request.magic is always 0?
  2. Beside this even the comment is empty??
  3. Beside this either in request or in trans the symbol is filled - is this a feature or a foul?   => SYM = StringLen(request.symbol)>1 ? request.symbol : trans.symbol?
  4. When I manually open and/or close a position OnTradeTransaction() is called but when I manually change SL and/or TP of an open position no reaction??

I the list of the open positions and orders I can see the magic number and the comment but all this is not assigned to either request, transaction and/or result...   :(


2022.12.29 10:06:59.427 Test OnTradeTransaction 02 (CADCHF,H1)  160  cadchf 152  penSTP Buy  Mag: 152  BUY Stop no SL & TP
2022.12.29 10:06:59.464 Test OnTradeTransaction 02 (CADCHF,H1)  265  CADCHF mag: >0<  cmmt: ><  New Event trans.typ: TRADE_TRANSACTION_ORDER_UPDATE  deal_typ: DEAL_TYPE_BUY  order_state: ORDER_STATE_PLACED  order_typ: ORDER_TYPE_BUY_STOP  order: 50311719794  pos: 0
2022.12.29 10:07:20.765 Test OnTradeTransaction 02 (CADCHF,H1)  265  CADCHF mag: >0<  cmmt: ><  New Event trans.typ: TRADE_TRANSACTION_ORDER_UPDATE  deal_typ: DEAL_TYPE_BUY  order_state: ORDER_STATE_PLACED  order_typ: ORDER_TYPE_BUY_STOP  order: 50311719794  pos: 0
2022.12.29 10:07:20.766 Test OnTradeTransaction 02 (CADCHF,H1)  265  CADCHF mag: >0<  cmmt: ><  New Event trans.typ: TRADE_TRANSACTION_ORDER_DELETE  deal_typ: DEAL_TYPE_BUY  order_state: ORDER_STATE_FILLED  order_typ: ORDER_TYPE_BUY_STOP  order: 50311719794  pos: 50311719794
2022.12.29 10:07:20.766 Test OnTradeTransaction 02 (CADCHF,H1)  265  CADCHF mag: >0<  cmmt: ><  New Event trans.typ: TRADE_TRANSACTION_HISTORY_ADD  deal_typ: DEAL_TYPE_BUY  order_state: ORDER_STATE_FILLED  order_typ: ORDER_TYPE_BUY_STOP  order: 50311719794  pos: 50311719794

Here is my little EA with which you can check yourself or tell me what I am doing wrong..

ONLY FOR DEMO ACCOUNTS!!


Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Trade Request Structure - Data Structures - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
In such matters I understand with the help of such spies.

Run it and in parallel do any trading operations manually or automatically. Then look at the file where the spy collected all the transaction data.

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

ФОРТС. Вопросы по исполнению

fxsaber, 2018.02.28 13:39

2018.02.28 14:28:27.907
Trans.deal = 0
Trans.order = 213465763
Trans.symbol = EURUSD
Trans.type = TRADE_TRANSACTION_ORDER_ADD (0)
Trans.order_type = ORDER_TYPE_SELL (1)
Trans.order_state = ORDER_STATE_STARTED (0)
Trans.deal_type = DEAL_TYPE_BUY (0)
Trans.time_type = ORDER_TIME_GTC (0)
Trans.time_expiration = 1970.01.01 00:00:00
Trans.price = 1.22178
Trans.price_trigger = 0.0
Trans.price_sl = 0.0
Trans.price_tp = 0.0
Trans.volume = 1.0
Trans.position = 0
Trans.position_by = 0
Request.action = ENUM_TRADE_REQUEST_ACTIONS::0 (0)
Request.magic = 0
Request.order = 0
Request.symbol = 
Request.volume = 0.0
Request.price = 0.0
Request.stoplimit = 0.0
Request.sl = 0.0
Request.tp = 0.0
Request.deviation = 0
Request.type = ORDER_TYPE_BUY (0)
Request.type_filling = ORDER_FILLING_FOK (0)
Request.type_time = ORDER_TIME_GTC (0)
Request.expiration = 1970.01.01 00:00:00
Request.comment = 
Request.position = 0
Request.position_by = 0
Result.retcode = 0
Result.deal = 0
Result.order = 0
Result.volume = 0.0
Result.price = 0.0
Result.bid = 0.0
Result.ask = 0.0
Result.comment = 
Result.request_id = 0
Result.retcode_external = 0

2018.02.28 14:28:27.913
Trans.deal = 196986814
Trans.order = 213465763
Trans.symbol = EURUSD
Trans.type = TRADE_TRANSACTION_DEAL_ADD (6)
....
 
Carl Schreiber:

Hi,

am I doing something wrong?

  1. To know where the calls of OnTradeTransaction() belong to I would like to use the magic number. The only (why only?) type that provides the magic number is request - BUT in OnTradeTransaction() request.magic is always 0?
  2. Beside this even the comment is empty??
  3. Beside this either in request or in trans the symbol is filled - is this a feature or a foul?   => SYM = StringLen(request.symbol)>1 ? request.symbol : trans.symbol?
  4. When I manually open and/or close a position OnTradeTransaction() is called but when I manually change SL and/or TP of an open position no reaction??

I the list of the open positions and orders I can see the magic number and the comment but all this is not assigned to either request, transaction and/or result...   :(


Here is my little EA with which you can check yourself or tell me what I am doing wrong..

ONLY FOR DEMO ACCOUNTS!!


If i recall correctly, there is always order or positionid, with those it it possible to retrieve the magic number from current positions or positions in history.

 
My EA is reduced to the core of my problem.
I started with something similar than your spy and then I noticed that important information for me is not delivered to my EA, although it exists in the system and I don't see any reason why this is so, except ... :(
 
Enrique Dangeroux #:

If i recall correctly, there is always order or positionid, with those it it possible to retrieve the magic number from current positions or positions in history.

This forces me to administrate theses ids additionally and make OnTradetransdaction() more or less  superfluous :(

 

I have never used the OnTradeTransaction but I do have questions, guesses and observations that might help ...

  1. Why are you trying to change the magic number in operations involving updating the T/P and S/L, instead of supplying the current magic number of the position/order in your request?
    ...
    req.magic = __LINE__; //PositionGetInteger(POSITION_MAGIC);   // MagicNumber der Position (Line 109)
    ...
    req.magic = __LINE__; //OrderGetInteger(ORDER_MAGIC);         // MagicNumber der Position (Line 187)
    ...
  2. It may be that with certain requests or transaction types (e.g. order update, or stops update), where things like magic number and comments that cannot be changed anyway, these are probably ignored and not carried over to the transaction event handler. This is only a guess.
  3. In my tests with your code, only the "TRADE_TRANSACTION_REQUEST" transaction type had a magic number and comment.
    2022.12.29 09:47:57.738 Test_OnTradeTransaction_02 (EURUSD,H1)  265  EURUSD mag: >127<  cmmt: >Market Sell Mag: 127<  New Event trans.typ: TRADE_TRANSACTION_REQUEST  deal_typ: DEAL_TYPE_BUY  order_state: ORDER_STATE_STARTED  order_typ: ORDER_TYPE_BUY  order: 0  pos: 0


 
It is annoying. I remembered spending a week to understand and get it working. There is no other way.
 
Why the hell the request that my EA send loses its magic number and its comment. If on the server side the request that is send back was nullified it only would be two code lines to assign this again :(
 
Fernando Carreiro #:

I have never used the OnTradeTransaction but I do have questions, guesses and observations that might help ...

  1. Why are you trying to change the magic number in operations involving updating the T/P and S/L, instead of supplying the current magic number of the position/order in your request?
  2. It may be that with certain requests or transaction types (e.g. order update, or stops update), where things like magic number and comments that cannot be changed anyway, these are probably ignored and not carried over to the transaction event handler. This is only a guess.
  3. In my tests with your code, only the "TRADE_TRANSACTION_REQUEST" transaction type had a magic number and comment.


add 1.: I just wanted to try it and to see what happens: Can I change the magic number of an open position or oder or will that cause this an error - but nothing! It is not checked and not handled...
             Imagine to check only the magic number that logs by its changes the management of this position -  only an idea..

add 3.: Right (why only this?), but it would be OK if were set correctly but I set them before sending my request to the server and this (?) request comes back without these MY information... :(

 
Carl Schreiber #: add 3.: Right (why only this?), but it would be OK if were set correctly but I set them before sending my request to the server and this (?) request comes back without these MY information... :(

I am guessing that for all other types, except for that one, the magic and comment fields are simply cleared and ignored because they are not used.

It could also be to save on network bandwidth, that only the minimal required data is transmitted to and from the trade server, and given that magic and comment is not required for all other types except the primary request, these are never send nor received and not part of the transaction event.

 
Fernando Carreiro #:

It could also be to save on network bandwidth, that only the minimal required data is transmitted to and from the trade server, and given that magic and comment is not required for all other types except the primary request, these are neve send nor received.

Won't be the field length the same no matter whether it was filled with 0 or the highest possible number?

Reason: