Download MetaTrader 5

Standard way to detect stop loss transaction executed on a position.

To add comments, please log in or register
Do you know that MQL5 has event handling?
nicolasxu
296
nicolasxu 2014.10.04 16:53 

 I've read this post. But I am still not clear. 

 Here is my log when stop loss is executed in strategy tester.

Now I have a position.

It looks like OnTradeTransaction() is triggered 3 times. 

The MqlTradeTransaction is: TRADE_TRANSACTION_HISTORY_ADD 

The MqlTradeTransaction is: TRADE_TRANSACTION_ORDER_DELETE 

The MqlTradeTransaction is: TRADE_TRANSACTION_DEAL_ADD 

position is closed.  

There is no transaction type called "stop_loss_executed". The right way to detect stop loss transaction is to do what?

My idea is if a position is closed, then it can be result from a stop loss on a position, or user manually send an order. There is no way to tell the difference. Is this correct? 

If I am wrong, please tell me how to detect a stop loss event. 

Here is my log for that minute when stop loss event is triggered. 

Thanks!

Files:
Alain Verleyen
Moderator
30727
Alain Verleyen 2014.10.04 18:59  
nicolasxu:

 I've read this post. But I am still not clear. 

 Here is my log when stop loss is executed in strategy tester.

Now I have a position.

It looks like OnTradeTransaction() is triggered 3 times. 

The MqlTradeTransaction is: TRADE_TRANSACTION_HISTORY_ADD 

The MqlTradeTransaction is: TRADE_TRANSACTION_ORDER_DELETE 

The MqlTradeTransaction is: TRADE_TRANSACTION_DEAL_ADD 

position is closed.  

There is no transaction type called "stop_loss_executed". The right way to detect stop loss transaction is to do what?

My idea is if a position is closed, then it can be result from a stop loss on a position, or user manually send an order. There is no way to tell the difference. Is this correct? 

If I am wrong, please tell me how to detect a stop loss event. 

Here is my log for that minute when stop loss event is triggered. 

Thanks!

You know your posittion (symbol, buy or sell), your volume, your sl price : EURUSD BUY 1.0 sl:1.27526

So if you detect a opposite deal, with the same volume and your sl price, it means stoploss has been triggered.

LO	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   The MqlTradeTransaction is: TRADE_TRANSACTION_DEAL_ADD
PM	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Symbol: EURUSD
GG	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Deal ticket: 5
IQ	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Deal type: DEAL_TYPE_SELL
LD	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Order ticket: 5
IS	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Order type: ORDER_TYPE_BUY
NL	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Order state: ORDER_STATE_STARTED
HI	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Order time type: ORDER_TIME_GTC
FQ	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Order expiration: 1970.01.01 00:00
CR	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Price: 1.27526
HJ	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Price trigger: 0
KL	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Stop Loss: 0
HE	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Take Profit: 0
QL	0	22:11:32.125	A1 (EURUSD,M1)	2014.09.26 03:00:39   Volume: 1
nicolasxu
296
nicolasxu 2014.10.05 03:38  
angevoyageur:

You know your posittion (symbol, buy or sell), your volume, your sl price : EURUSD BUY 1.0 sl:1.27526

So if you detect a opposite deal, with the same volume and your sl price, it means stoploss has been triggered.

Got it. Thanks!
To add comments, please log in or register