Stefano Piovesan:
Is it possible to be notified of the stop loss execution of a placed order in the EA, without looking at the trade history?
If I have to look at history, I must send a PostMessageA(
- You know the TP/SL/OrderType/OrderOpenTime. If the order is no longer in the pool, get HH/LL for the time it was open and figure which was hit.
- You never need your PostMessage. The order will be in current history, remember the result - don't keep looking months later.
I place an order with take profit and stop loss within an EA.
Is it possible to be notified of the stop loss execution of a placed order in the EA, without looking at the trade history?
If I have to look at history, I must send a PostMessageA(main, WM_COMMAND, MT4_WMCMD_ALL_HISTORY, 0); that requires an "allow dll import", that I would like to avoid.
Example: Stop Loss Take Profit
...
If a trade is closed by Stop loss, the volume is doubled; if it's closed by Take profit the minimum volume is used. OnTradeTransaction is used to determine whether a trade was performed after the activation of Stop loss or Take profit.
The excellent enumeration ENUM_DEAL_REASON was added in build 1625:
ENUM_DEAL_REASON | Reason description |
---|---|
... | ... |
DEAL_REASON_SL | The operation was executed as a result of Stop Loss activation |
DEAL_REASON_TP | The operation was executed as a result of Take Profit activation |
... | ... |
It can be checked in OnTradeTransaction.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I place an order with take profit and stop loss within an EA.
Is it possible to be notified of the stop loss execution of a placed order in the EA, without looking at the trade history?
If I have to look at history, I must send a PostMessageA(main, WM_COMMAND, MT4_WMCMD_ALL_HISTORY, 0); that requires an "allow dll import", that I would like to avoid.