Detect stop trigger in OnTradeTransaction backtest - page 2

To add comments, please log in or register
Alain Verleyen
39019
Alain Verleyen  
chinaski:

Hello angevoyageur,

find attached a simple EA which demonstrates the problem. The EA opens long along with stop and target then short, then long and so on.

A dump method is also contained. Just apply EUR.USD 1 minute 1 week and watch the transaction dumps in backtest log.

Thank you for help. 

Here your stoploss is triggered :

2013.05.03 16:52106EURUSDbuyin0.011.312401060.000.000.009 978.84
2013.05.03 18:35107EURUSDsellout0.011.310401070.000.00-2.009 976.84sl 1.31040

2013.05.07 18:45:27    Core 1    2013.05.03 18:35:40   trans=symbol=EURUSD price=1.3104000 volume=0.01 sl=0.0000000 tp=0.0000000 order=107 deal=107 entry-type=IN trans-type=DEAL_ADD order_type=BUY deal_type=DEAL_TYPE_SELL type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit

chinaski
985
chinaski  
angevoyageur:

Here your stoploss is triggered :

2013.05.03 16:52106EURUSDbuyin0.011.312401060.000.000.009 978.84
2013.05.03 18:35107EURUSDsellout0.011.310401070.000.00-2.009 976.84sl 1.31040

2013.05.07 18:45:27    Core 1    2013.05.03 18:35:40   trans=symbol=EURUSD price=1.3104000 volume=0.01 sl=0.0000000 tp=0.0000000 order=107 deal=107 entry-type=IN trans-type=DEAL_ADD order_type=BUY deal_type=DEAL_TYPE_SELL type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit

Hello,

but this is entry-type=IN , not out....

Alain Verleyen
39019
Alain Verleyen  
chinaski:

Hello,

but this is entry-type=IN , not out....

Maybe, but it's your sl triggered nevertheless. Never religiously believe what a program tells you ;-)
chinaski
985
chinaski  
angevoyageur:
Maybe, but it's your sl triggered nevertheless. Never religiously believe what a program tells you ;-)

You are right, on the other hand, how can i know that i can rely on sl=0.0 and tp=0.0 means this is stop or target order and not: sl and tp simply missed (in the transaction structure)..?

Alain Verleyen
39019
Alain Verleyen  
chinaski:

You are right, on the other hand, how can i know that i can rely on sl=0.0 and tp=0.0 means this is stop or target order and not: sl and tp simply missed (in the transaction structure)..?

A structure can't have missing field. This is transaction about a deal (DEAL_TYPE_SELL), a deal can't have a SL/TP, that make no sense. A SL (or TP) is an order (a sort of special pending order), when it is triggered, the order result in a deal. You can check all of that within OnTradeTransaction.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties - Documentation on MQL5
chinaski
985
chinaski  
angevoyageur:

A structure can't have missing field. This is transaction about a deal (DEAL_TYPE_SELL), a deal can't have a SL/TP, that make no sense. A SL (or TP) is an order (a sort of special pending order), when it is triggered, the order result in a deal. You can check all of that within OnTradeTransaction.

I do not mean the structure members of course;i mean values.
Alain Verleyen
39019
Alain Verleyen  
chinaski:
I do not mean the structure members of course;i mean values.
So? It is a little confusing, can I still help?
chinaski
985
chinaski  
angevoyageur:
So? It is a little confusing, can I still help?

Yes, was a help. What do mean byconfusing? I wondered about getting always ENTRY_IN. You said never believe on what program tells me. I say, you are right, so sl=0.0 or tp=0.0 (missed values) could also a mistake by server - forgot to wroite values.

What is important for me: a save method to determine what transaction is stop out. MT is great but in many aspects, confusing, not doing what you normally would expect, like in this case.

Do you know what i mean ? 

Alain Verleyen
39019
Alain Verleyen  
chinaski:

Yes, was a help. What do mean byconfusing? I wondered about getting always ENTRY_IN. You said never believe on what program tells me. I say, you are right, so sl=0.0 or tp=0.0 (missed values) could also a mistake by server - forgot to wroite values.

What is important for me: a save method to determine what transaction is stop out. MT is great but in many aspects, confusing, not doing what you normally would expect, like in this case.

Do you know what i mean ? 

It is I who am confused;-) I read and respond to many subjects. I understand what you said, must be able to change the habits with MT4.
Alain Verleyen
39019
Alain Verleyen  
chinaski:

Yes, was a help. What do mean byconfusing? I wondered about getting always ENTRY_IN. You said never believe on what program tells me. I say, you are right, so sl=0.0 or tp=0.0 (missed values) could also a mistake by server - forgot to wroite values.

What is important for me: a save method to determine what transaction is stop out. MT is great but in many aspects, confusing, not doing what you normally would expect, like in this case.

Do you know what i mean ? 

I checked. When a SL/TP is triggered you have these transaction :

  1. TRADE_TRANSACTION_POSITION with SL and TP setted (but no deal yet), then
  2. TRADE_TRANSACTION_DEAL_ADD

TRADE_TRANSACTION_POSITION

Changing a position not related to a deal execution. This type of transaction shows that a position has been changed on a trade server side. Position volume, open price, Stop Loss and Take Profit levels can be changed. Data on changes are submitted in MqlTradeTransaction structure via OnTradeTransaction handler. Position change (adding, changing or closing), as a result of a deal execution, does not lead to the occurrence of TRADE_TRANSACTION_POSITION transaction.

To add comments, please log in or register