Detect stop trigger in OnTradeTransaction backtest - page 4

 
angevoyageur:

So, we are talking about backtesting only. I have tested with my own code and I obtain 3 transactions when a stop is triggered :

2013.05.15 10:22:27    Core 1    2013.05.10 16:20:37   Symbol : EURUSD  event : TRADE_TRANSACTION_DEAL_ADD(6)
2013.05.15 10:22:27    Core 1    2013.05.10 16:20:37   Symbol : EURUSD  event : TRADE_TRANSACTION_ORDER_DELETE(2)
2013.05.15 10:22:27    Core 1    2013.05.10 16:20:37   Symbol : EURUSD  event : TRADE_TRANSACTION_HISTORY_ADD(3)

With the DEAL_ADD I get the price of the deal, so the SL in my case. All seems correct to me. I suggest you send me the code you use, the backtest log (as a file) and a screenshot of Strategy tester Settings. Then I can reproduce the exact same test as yours and analyse the result. You can send me a PM if you prefer.

Hello,

can you tell me where exactly the executed stop or target price is stored:

a) MqlTradeTransaction

b) MqlTradeRequest

c) MqlTradeResult

along with member. What MetaTrader server ?

Thank you 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure - Documentation on MQL5
 
angevoyageur:

So, we are talking about backtesting only. I have tested with my own code and I obtain 3 transactions when a stop is triggered :

2013.05.15 10:22:27    Core 1    2013.05.10 16:20:37   Symbol : EURUSD  event : TRADE_TRANSACTION_DEAL_ADD(6)
2013.05.15 10:22:27    Core 1    2013.05.10 16:20:37   Symbol : EURUSD  event : TRADE_TRANSACTION_ORDER_DELETE(2)
2013.05.15 10:22:27    Core 1    2013.05.10 16:20:37   Symbol : EURUSD  event : TRADE_TRANSACTION_HISTORY_ADD(3)

With the DEAL_ADD I get the price of the deal, so the SL in my case. All seems correct to me. I suggest you send me the code you use, the backtest log (as a file) and a screenshot of Strategy tester Settings. Then I can reproduce the exact same test as yours and analyse the result. You can send me a PM if you prefer.

If you mean TRADE_TRANSACTION_DEAL_ADD and MqlTradeTransaction.price, this price is always 0.

Even if i do not filter for  TRADE_TRANSACTION_DEAL_ADD, the price is always 0, after entry order sent out.

I use

CTrade.Buy(...)  // place entry

 

and

 

CTrade.PositionModify // to attach stop and target

 

and

void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {
...
}

 to catch transactions.

 
chinaski:

If you mean TRADE_TRANSACTION_DEAL_ADD and MqlTradeTransaction.price, this price is always 0.

Even if i do not filter for  TRADE_TRANSACTION_DEAL_ADD, the price is always 0, after entry order sent out.

I use

 

and

 

 

and

 to catch transactions.

This is with MqlTradeTransaction.price, it's not always 0.

2013.05.15 10:22:27     Core 1  2013.05.10 16:20:37   stop loss triggered buy 0.10 EURUSD 1.30163 sl: 1.29663 tp: 1.30663 [#47 sell 0.10 EURUSD at 1.29663]
2013.05.15 10:22:27     Core 1  2013.05.10 16:20:37   deal #47 sell 0.10 EURUSD at 1.29663 done (based on order #47)
2013.05.15 10:22:27     Core 1  2013.05.10 16:20:37   deal performed [#47 sell 0.10 EURUSD at 1.29663]
2013.05.15 10:22:27     Core 1  2013.05.10 16:20:37   order performed sell 0.10 at 1.29663 [#47 sell 0.10 EURUSD at 1.29663]
2013.05.15 10:22:27     Core 1  2013.05.10 16:20:37   ----------------TRANSACTION START---------------------------
2013.05.15 10:22:27     Core 1  2013.05.10 16:20:37   Symbol : EURUSD  event : TRADE_TRANSACTION_DEAL_ADD(6)
2013.05.15 10:22:27     Core 1  2013.05.10 16:20:37   Order #47  type : ORDER_TYPE_BUY(0)  state : ORDER_STATE_STARTED(0)
2013.05.15 10:22:27     Core 1  2013.05.10 16:20:37   Deal #47 type : DEAL_TYPE_SELL(1)
2013.05.15 10:22:27     Core 1  2013.05.10 16:20:37   Price = 1.29663 Volume = 0.1 SL = 0.0 TP = 0.0 Activation price = 0.0

There is something weird in your results, but I can't see what with the code you provide.

 

Here the log with your EA tc_ea_trans :

2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   take profit triggered buy 0.01 EURUSD 1.31553 sl: 1.31503 tp: 1.31603 [#331 sell 0.01 EURUSD at 1.31603]
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   deal #331 sell 0.01 EURUSD at 1.31603 done (based on order #331)
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   deal performed [#331 sell 0.01 EURUSD at 1.31603]
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   order performed sell 0.01 at 1.31603 [#331 sell 0.01 EURUSD at 1.31603]
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   price corrected from 1.31609 to 1.31604, deviation: 10 (instant sell 0.01 EURUSD at 1.31609 sl: 1.31659 tp: 1.31559)(1.31604 / 1.31609 / 1.31604)
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   instant sell 0.01 EURUSD at 1.31604 sl: 1.31659 tp: 1.31559 (1.31604 / 1.31609 / 1.31604)
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   deal #332 sell 0.01 EURUSD at 1.31604 done (based on order #332)
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   deal performed [#332 sell 0.01 EURUSD at 1.31604]
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   order performed sell 0.01 at 1.31604 [#332 sell 0.01 EURUSD at 1.31604]
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   CTrade::OrderSend: instant sell 0.01 EURUSD at 1.31609 sl: 1.31659 tp: 1.31559 [done at 1.31604]
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   TRADE_TRANSACTION_DEAL_ADD
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   trans=symbol=EURUSD price=1.3160300 volume=0.01 sl=0.0000000 tp=0.0000000 order=331 deal=331 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
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   TRADE_TRANSACTION_ORDER_DELETE
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   trans=symbol=EURUSD price=1.3160300 volume=0.01 sl=0.0000000 tp=0.0000000 order=331 deal=0 entry-type=IN trans-type=ORDER_DELETE order_type=SELL deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 prof
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   TRADE_TRANSACTION_HISTORY_ADD
2013.05.15 18:43:48     Core 1  2013.05.02 08:39:15   trans=symbol=EURUSD price=1.3160300 volume=0.00 sl=0.0000000 tp=0.0000000 order=331 deal=0 entry-type=IN trans-type=HISTORY_ADD order_type=SELL deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profi
 

Hello Angevoyageur,

find attached again  simple EA. This should demonstrate it. It just places an order with tight stop and target (input param) and logs each transaction. 

I really appreciate your help.

(Perhaps you can also show your entry transactions) 

 

Could you also give me mt-server ip ? 

Files:
tc_ea_trans.mq5  11 kb
 
chinaski:

Hello Angevoyageur,

find attached again  simple EA. This should demonstrate it. It just places an order with tight stop and target (input param) and logs each transaction. 

I really appreciate your help.

(Perhaps you can also show your entry transactions) 

 

Could you also give me mt-server ip ? 

I use the EA you just posted. MQ demo, Access point Europe. Backtesting with :


I take an random excerpt from the log :

2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   take profit triggered buy 0.01 EURUSD 1.31751 sl: 1.31681 tp: 1.31821 [#107 sell 0.01 EURUSD at 1.31821]
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   deal #107 sell 0.01 EURUSD at 1.31821 done (based on order #107)
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   deal performed [#107 sell 0.01 EURUSD at 1.31821]
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   order performed sell 0.01 at 1.31821 [#107 sell 0.01 EURUSD at 1.31821]
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   requote 1.31823 / 1.31836 / 1.31823 (instant sell 0.01 EURUSD at 1.31836 sl: 1.31906 tp: 1.31766)
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   CTrade::OrderSend: instant sell 0.01 EURUSD at 1.31836 sl: 1.31906 tp: 1.31766 [requote (1.31823/1.31836)]
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   instant buy 0.01 EURUSD at 1.31840 sl: 1.31770 tp: 1.31910 (1.31827 / 1.31840 / 1.31827)
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   deal #108 buy 0.01 EURUSD at 1.31840 done (based on order #108)
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   deal performed [#108 buy 0.01 EURUSD at 1.31840]
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   order performed buy 0.01 at 1.31840 [#108 buy 0.01 EURUSD at 1.31840]
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   CTrade::OrderSend: instant buy 0.01 EURUSD at 1.31840 sl: 1.31770 tp: 1.31910 [done at 1.31840]
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   trans=symbol=EURUSD price=1.3182100 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
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   trans=symbol=EURUSD price=1.3182100 volume=0.01 sl=0.0000000 tp=0.0000000 order=107 deal=0 entry-type=IN trans-type=ORDER_DELETE order_type=SELL deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 prof
2013.05.15 21:54:11     Core 1  2013.05.01 20:02:15   trans=symbol=EURUSD price=1.3182100 volume=0.00 sl=0.0000000 tp=0.0000000 order=107 deal=0 entry-type=IN trans-type=HISTORY_ADD order_type=SELL deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profi

So, you still have a problem detecting a SL/TP triggered ?

Files:
 
angevoyageur:

I use the EA you just posted. MQ demo, Access point Europe. Backtesting with :


I take an random excerpt from the log :

So, you still have a problem detecting a SL/TP triggered ?

oh. i see.i could swere in my runs yesterday there was no such price given. I made a text search for this price in the backtest log.

But now, i can see this transaction AFTER logentry 

 

"take profit triggered "

 

in my lastest run as well - along with execution price.

I apologize for all the time it takes.

 
chinaski:

oh. i see.i could swere in my runs yesterday there was no such price given. I made a text search for this price in the backtest log.

But now, i can see this transaction AFTER logentry 

...
The log I provided you is from the Viewer, when you read the log directly from Strategy Tester Journal tab, it is displayed in the reverse order.
 
angevoyageur:
The log I provided you is from the Viewer, when you read the log directly from Strategy Tester Journal tab, it is displayed in the reverse order.
i usually open the logfile from backtest log-tab, where order is from top to down. So in fact, the logentry indicating price is written before the transaction occurs.
 

Hello Angevoyageur, 

Access point Europe. Backtesting with : "

can you give me complete IP of this server ? 

Reason: