Errors, bugs, questions - page 480

 
papaklass:
Now updated and trying to figure it out again. I've put prints on almost every line. I will report the results.

Here's the run with your insert, the moment the stop loss was fixed:

2011.08.09 00:41:08 Core 1 2011.01.14 01:41:27 Long position by EURUSD to be closed of stop-loss
2011.08.09 00:41:08 Core 1 2011.01.14 01:41:27 -----------------Deal #63 sl 1.33328
2011.08.09 00:41:08 Core 1 2011.01.01.14 01:41:27 oldDealsTotal=62 newDealsTotal=63
2011.08.09 00:41:08 Core 1 2011.01.14 01:41:27 CSampleExpert::Trade
2011.08.09 00:41:08 Core 1 2011.01.14 01:41:27 order performed sell 0.15 at 1.33328 [#63 sell 0.15 EURUSD at 1.33328]
2011.08.09 00:41:08 Core 1 2011.01.14 01:41:27 deal performed [#63 sell 0.15 EURUSD at 1.33328]
2011.08.09 00:41:08 Core 1 2011.01.14 01:41:27 deal #63 sell 0.15 EURUSD at 1.33328 done (based on order #63)
2011.08.09 00:41:08 Core 1 2011.01.14 01:41:27 stop loss triggered buy 0.15 EURUSD 1.32127 sl: 1.33328 tp: 1.35139 [#63 sell 0.15 EURUSD at 1.33328]
2011.08.09 00:41:08 Core 1 2011.01.13 18:32:00 Long position by EURUSD to be modified trailing
 
Obviously the different result is different processing in OnTrade, I am only looking for trades, only they interest me, you on the other hand I understand you are processing all events by classifying them and there is something messed up here somewhere.
 
I take it that the futures betting market is also a demo? Took the bet from the MMVB real, the lots do not match.
 
papaklass:

I place pending orders with a lifetime of 1 hour. After one hour, the orders which have not been activated are closed by the expiry time of the order. If several orders are closed simultaneously, and before closing, the HistoryOrdersTotal() function had a non-zero value, then it loses some orders. For example, before the closing of 8 orders, the function had a value of 4, but after the closing, it has a value of 10. Two orders are lost.


What do you mean by "Orders were lost"? It should be borne in mind that messages coming to OnTrade() may carry information about more than one trade event. In addition, if several messages are sent simultaneously, when processing the first message, the historical cache may already have changed, and you may get a feeling of "lost events".

Please read the article Trade events in MetaTrader 5:

Conclusion

All operations in the MetaTrader 5 trading platform are asynchronous, and sending messages on all changes in the trading account are made independently of each other, so do not try to trace a single event according to the "One request - One trade event" rule. If you want to determine exactly what has changed after the Trade event, you need to analyze all deals, positions and orders at each call of the handler OnTrade and compare them with the state that was before the event appeared.
 
papaklass:
I specifically requested the HistoryOrdersTotal() value, which was equal to 4, before closing the orders. After closing 8 orders, the value of HistoryOrdersTotal() should have been equal to 12 (4 + 8), but it was equal to 10. I have attached a log file, we can see similar situations in it more than once. I've also attached the Expert Advisor, with which this is obtained. Do it yourself and you will see everything.

Try changing the function, what will happen?

void OnTrade(){
//---
   HistorySelect(dayStart,TimeTradeServer());      
   Print("              ",__FUNCTION__,"  :  historyOrdersTotal = ",HistoryOrdersTotal(),"   ",TimeTradeServer()); 
}
     
 
The HTML report from the tester run is not always saved to a file?!
 
zigan:
The HTML report from the tester run is not always saved to a file!

Describe more precisely. Under what circumstances.

 
alexvd:

Describe more precisely. Under what circumstances.

Rarely, about one out of 20-30 tester runs - open "Results" tab

click save XML report - I get the report file, everything is OK!

click save HTML report - window for saving file pops up, hangs with empty ProgressBar for a while (briefly), then ProgressBar fills quickly and window closes... But no report file is created!

I can't specify a pattern for when exactly this happens.

 
Rosh:

Try changing the function, what will happen?

I don't think this would help. OnTrade, as a matter of principle, cannot work the way papaklass does.

The key is"you need to analyse all trades, positions and orders on each call to the OnTrade handler and compare it with the state it was in before it appeared" . In the example at with pending orders, this only applies to orders in the history. To avoid losing orders, I would change the code in this way:

Introduce a global variable int oldHistoryOrders; and in Ontrade, something like this:

//--------------------------ТОРГОВЫЕ СОБЫТИЯ-------------------------------------------------------------+
void OnTrade(){
//---
   Print(__FUNCTION__);
   HistorySelect(0,TimeCurrent()+1);      
   int newHistoryOrders=HistoryOrdersTotal();
   if(oldHistoryOrders==newHistoryOrders) return;
   Print("oldHistoryOrders=",oldHistoryOrders," newHistoryOrders=",newHistoryOrders);
   for(int i=oldHistoryOrders;i<newHistoryOrders;i++)
      Print("Order ",i," #",HistoryOrderGetTicket(i));
   oldHistoryOrders=newHistoryOrders;    
//   Print("              ",__FUNCTION__,"  :  historyOrdersTotal = ",newHistoryOrders,"   ",dayStart); 
}
Files:
 
papaklass:

This is not how I work with OnTrade() as you described. In my attached code, I have removed everything, leaving only the part that highlights the function's bug. I have practically no loops in my EA. The EA handles a single symbol on a single tick. Therefore, I do not need cycles. I process all symbols within 12 ticks.

PS: OnTrade() informs me about a trade event. And what event has occurred is defined by my functions without loops.

Well, okay, I was only referring to your example that proves, supposedly, the loss of orders by the OnTrade function. OnTrade works asynchronously, not by ticks, so it doesn't care how many symbols you process in a tick. You have a bunch of empty orders expire at one time, so you can't do without the workaround. I have changed your code to show that OnTrade does not miss anything. I even ran it in the tester and everything seems to be in place. The tickers of all deletedorders printed by the printer from OnTrade are present in the log. Have you tried my version?
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - Документация по MQL5
Reason: