
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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-loss2011.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
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.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?
The HTML report from the tester run is not always saved to a file!
Describe more precisely. Under what circumstances.
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.
Try changing the function, what will happen?
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:
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.