Open Buy position with SL and TP.
TP triggered.
Result:
2019.02.01 23:57:59 Deal: 2019.02.01 23:57:59 |Ticket |Order |Time |Time msc |Type |Entry |Magic |Reason |Position ID 2019.02.01 23:57:59 |1 |0 |2019.01.04 00:00:00 |1546560000000 |DEAL_TYPE_BALANCE |DEAL_ENTRY_IN |0 |DEAL_REASON_CLIENT |0 2019.02.01 23:57:59 |Volume |Price |Commission |Swap |Profit |Symbol |Comment |External ID 2019.02.01 23:57:59 |0.00 |0.00000 |0.00 |0.00 |3000.00 | | | 2019.02.01 23:57:59 Order 0 is not found in the trade history between the dates 2019.01.03 23:00:00 and 2019.02.02 00:57:59 2019.02.01 23:57:59 2019.02.01 23:57:59 Deal: 2019.02.01 23:57:59 |Ticket |Order |Time |Time msc |Type |Entry |Magic |Reason |Position ID 2019.02.01 23:57:59 |2 |2 |2019.01.04 00:00:00 |1546560000100 |DEAL_TYPE_BUY |DEAL_ENTRY_IN |753 |DEAL_REASON_EXPERT |2 2019.02.01 23:57:59 |Volume |Price |Commission |Swap |Profit |Symbol |Comment |External ID 2019.02.01 23:57:59 |0.30 |1.13931 |0.00 |0.00 |0.00 |EURUSD | | 2019.02.01 23:57:59 Order: 2019.02.01 23:57:59 |Ticket |Time setup |Type |State |Time expiration |Time done |Time setup msc |Time done msc |Type filling 2019.02.01 23:57:59 |2 |2019.01.04 00:00:00 |ORDER_TYPE_BUY |ORDER_STATE_FILLED |2019.01.04 00:00:00 |2019.01.04 00:00:00 |1546560000100 |1546560000100 |ORDER_FILLING_FOK 2019.02.01 23:57:59 |Type time |Magic |Reason |Position id |Position by id 2019.02.01 23:57:59 |1970.01.01 00:00:00 |753 |ORDER_REASON_EXPERT |2 |0 2019.02.01 23:57:59 |Volume initial |Volume current |Open price |sl |tp |Price current |Price stoplimit 2019.02.01 23:57:59 |0.30 |0.00 |1.13931 |1.13431 |1.14431 |1.13923 |0.00000 2019.02.01 23:57:59 |Symbol |Comment |Extarnal id 2019.02.01 23:57:59 |EURUSD | | 2019.02.01 23:57:59 2019.02.01 23:57:59 Deal: 2019.02.01 23:57:59 |Ticket |Order |Time |Time msc |Type |Entry |Magic |Reason |Position ID 2019.02.01 23:57:59 |3 |3 |2019.01.07 11:12:14 |1546859534000 |DEAL_TYPE_SELL |DEAL_ENTRY_OUT |753 |DEAL_REASON_TP |2 2019.02.01 23:57:59 |Volume |Price |Commission |Swap |Profit |Symbol |Comment |External ID 2019.02.01 23:57:59 |0.30 |1.14431 |0.00 |-0.21 |150.00 |EURUSD |tp 1.14431 | 2019.02.01 23:57:59 Order: 2019.02.01 23:57:59 |Ticket |Time setup |Type |State |Time expiration |Time done |Time setup msc |Time done msc |Type filling 2019.02.01 23:57:59 |3 |2019.01.07 11:12:14 |ORDER_TYPE_SELL |ORDER_STATE_FILLED |2019.01.07 11:12:14 |2019.01.07 11:12:14 |1546859534000 |1546859534000 |ORDER_FILLING_IOC 2019.02.01 23:57:59 |Type time |Magic |Reason |Position id |Position by id 2019.02.01 23:57:59 |1970.01.01 00:00:00 |753 |ORDER_REASON_TP |2 |0 2019.02.01 23:57:59 |Volume initial |Volume current |Open price |sl |tp |Price current |Price stoplimit 2019.02.01 23:57:59 |0.30 |0.00 |1.14431 |0.00000 |0.00000 |1.14431 |0.00000 2019.02.01 23:57:59 |Symbol |Comment |Extarnal id 2019.02.01 23:57:59 |EURUSD |tp 1.14431 | 2019.02.01 23:57:59
Files:
HistoryDeals.mq5
29 kb
That is, when Stop Loss or Take Profit is triggered, there is always a deal DEAL_TYPE_SELL
or DEAL_TYPE_BUY (order ORDER_TYPE_SELL or ORDER_TYPE_BUY).
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
- www.mql5.com
A deal is the reflection of the fact of a trade operation execution based on an order that contains a trade request. Each trade is described by properties that allow to obtain information about it. In order to read values of properties, functions of the Identifier of a position, in the opening, modification or closing of which this deal...
Thanks! I was sure about the ENUM_DEAL_TYPE, was just wondering about ENUM_ORDER_TYPE - my feeling was that it is ORDER_TYPE_BUY or ORDER_TYPE_SELL, as SL / TP is by definition a market order - so glad to see that it is in fact handled this way.
So I assume that the same story is with the Stop Out, as it is kind of SL implemented on the broker side.
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
- www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The...
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
Just wondering before I potentially spend time on simulating it from EA code - has someone already checked what kind of ENUM_ORDER_TYPE of historical orders correspond with the occurrence of the following DEAL reasons? I mean, ORDER_TYPE_BUY / ORDER_TYPE_SELL or ORDER_TYPE_BUY_STOP / ORDER_TYPE_SELL_STOP?
DEAL_REASON_SL
The deal was executed as a result of Stop Loss activation
DEAL_REASON_TP
The deal was executed as a result of Take Profit activation
DEAL_REASON_SO
The deal was executed as a result of the Stop Out event
There definitely is some order behind, as the OnTradeTransaction() event handler, when handling SL/TP activation on a position, comes up with a following sequence of trade transaction events:
TRADE_TRANSACTION_POSITION -> TRADE_TRANSACTION_ORDER_UPDATE -> TRADE_TRANSACTION_DEAL_ADD -> TRADE_TRANSACTION_ORDER_DELETE -> TRADE_TRANSACTION_HISTORY_ADD
So the ocurrence of TRADE_TRANSACTION_HISTORY_ADD suggests that there is an order added to history after SL/TP activation.