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
Here are the log entries of a position closed by a triggered Take Profit. How can this detected in OnTradeTransaction( const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result)??
Neither the return code of const MqlTradeResult& result (result.retcode) is set (0 is no option, TRADE_RETCODE_DONE = 10009) nor one of the ids (Deal ticket, Order ticket, Request ID ) in order to find them without looping every time through all deal.
This is the Print at line #376 that print the relevant(?) flags:
And this is what I can read in the journal:
10:04:40 take profit triggered #2 sell 0.01 EURUSD 1.00319 sl: 1.00816 tp: 1.00171 [#3 buy 0.01 EURUSD at 1.00171]
10:04:40 deal #3 buy 0.01 EURUSD at 1.00171 done (based on order #3)
10:04:40 deal performed [#3 buy 0.01 EURUSD at 1.00171]
10:04:40 order performed buy 0.01 at 1.00171 [#3 buy 0.01 EURUSD at 1.00171]
10:04:40 373 New trade operation dTime1970.01.01 09:03:41
10:04:40 376 0 prc:trans.price=1.00171 tckt: 2 Tr.Type: TRADE_TRANSACTION_DEAL_ADD Tr.OrdType: ORDER_TYPE_BUY Tr.OrdFill: ORDER_STATE_STARTED Tr.tckt:3 2 0 retCode:0 0 0 0 0
10:04:40 489 MqlTradeTransaction: TRADE_TRANSACTION_DEAL_ADD deal #3 DEAL_TYPE_BUY EURUSD 0.01 lot
10:04:40 376 1 prc:trans.price=1.00171 tckt: 2 Tr.Type: TRADE_TRANSACTION_ORDER_DELETE Tr.OrdType: ORDER_TYPE_BUY Tr.OrdFill: ORDER_STATE_FILLED Tr.tckt:3 2 0 retCode:0 0 0 0 0
10:04:40 383 1 prc:trans.price=1.00171 tckt: 2 res.Ord:0 Tr.Type: TRADE_TRANSACTION_ORDER_DELETE Tr.OrdFill: ORDER_STATE_FILLED Tr.OrdType: ORDER_TYPE_BUY Tr.tckt:3 2 0 Res::0 0 0 0 0
10:04:40 408 PosExists #3 2 mag:0 ORDER_STATE_FILLED ORDER_TYPE_BUY
10:04:40 376 2 prc:trans.price=1.00171 tckt: 2 Tr.Type: TRADE_TRANSACTION_HISTORY_ADD Tr.OrdType: ORDER_TYPE_BUY Tr.OrdFill: ORDER_STATE_FILLED Tr.tckt:3 2 0 retCode:0 0 0 0 0
10:04:40 408 PosExists #3 2 mag:0 ORDER_STATE_FILLED ORDER_TYPE_BUY
2022.09.26 14:08:33.755 disconnected
The terminal writes so beautifully "take profit triggered #2 sell 0.01 EURUSD 1.00319 sl: 1.00816 tp: 1.00171 [#3 buy 0.01 EURUSD at 1.00171]"
So why the hell isn't there a flag like TRADE_TRANSACTION_TRIGGERED_PT and TRADE_TRANSACTION_TRIGGERED_SL??
And is the return code of the request always not set?
Denis, thank you for the article! I read it with interest, but I have not yet fully realised what I have read. I also downloaded your TradeProcessor Expert Advisor and ran it on my terminal, where I currently have an open position. I looked at the printouts and immediately some questions appeared, to which I want to find answers on my own. Well, if I can't do it, I will have to bother you. ))
Regards, Vladimir.
Regards, Vladimir.
Thank you for your opinion. You are welcome, MrBrooklin! ))
Thank you for your opinion. You are welcome, MrBrooklin! ))
Denis, sorry, but without your help my mind "explodes". Here is the result of one of the passes of your EA (by the way, a very cool EA!!!):
What I don't understand:
ENUM_DEAL_TYPE
Identifier
Description
DEAL_TYPE_BUY
Buy
Question - how when modifying a pending order SELL_STOP the transaction type is determined to BUY????? ))
Regards, Vladimir.
And there is no transaction. Placing a pending order and its processing does not entail any transaction. Trade ticket = 0, type = 0, where 0 is equivalent to DEAL_TYPE_BUY for the enumeration ENUM_DEAL_TYPE. That is, in the MqlTradeTransaction trans structure , some fields are populated and some are not. The unfilled fields are usually nulled.
More details: in the Documentation about pending orders.
The deal field will be populated for a transaction of this type:
TRADE_TRANSACTION_DEAL_*
The following fields are populated in the MqlTradeTransaction structure for trade transactions related to transaction processing (TRADE_TRANSACTION_DEAL_ADD, TRADE_TRANSACTION_DEAL_UPDATE and TRADE_TRANSACTION_DEAL_DELETE):
Only 3 types of transactions belong to "deal" types: TRADE_TRANSACTION_DEAL_ADD, TRADE_TRANSACTION_DEAL_UPDATE, TRADE_TRANSACTION_DEAL_DELETE.
And there is no transaction. Placing a pending order does not entail any transaction. Trade ticket = 0, type = 0, where 0 is equivalent to DEAL_TYPE_BUY for the enumeration ENUM_DEAL_TYPE. That is, in the MqlTradeTransaction trans structure , some fields are populated and some are not. The unfilled fields are usually zeroed.
More details: in the Documentation about pending orders.
Ahhhh, that's it!!! Man, it broke my head! ))
Thank you!!!
Regards, Vladimir.