Order stop loss notification

 

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.

Basic Principles - Trading Operations - MetaTrader 5
Basic Principles - Trading Operations - MetaTrader 5
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
 

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(

  1. 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.
  2. You never need your PostMessage. The order will be in current history, remember the result - don't keep looking months later.
 
Stefano Piovesan:

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_REASONReason description
......
DEAL_REASON_SLThe operation was executed as a result of Stop Loss activation
DEAL_REASON_TPThe operation was executed as a result of Take Profit activation
......

It can be checked in OnTradeTransaction.

Reason: