![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Maybe, we need PositionTotal()?
And what does this have to do with the position if I ask OrdersTotal() how many orders are currently placed?
And I request this information in OnTrade(), the moment when the order exists cannot be missed.
But in fact, it turns out that this moment is missed anyway and the requests are processed either when the order is not yet present or when it is already present.
But the moment when it exists is not detected in OnTrade(), or else, the OrdersTotal() lies.
To avoid complaining about the code imperfection, here is the MetaQuotes code with my improvement of the script in the Expert Advisor.
Added OnTrade() function and put the script code to OnInit().
Not a single print displays a message that there is an order.
I can only answer this with an article Trade events in MetaTrader 5:
Заключение
All operations in the MetaTrader 5 trading and analytical platform are asynchronous, and all changes in the trading account are reported independently of each other. Therefore you should not try to track a single event according to the "One request - One trade event" rule. If we want to determine exactly what has changed after the Trade event, we need to analyze all deals, positions and orders at each call of the handler OnTrade and compare them with the state we had before the event appeared.I can only answer this with the article Trading Events in MetaTrader 5:
This means that the order you are trying to catch should probably already be searched using HistoryOrdersTotalI am guided by this article. I would like to find out the answer to the question: how is it possible that a trade event misses the moment when an order is placed but has not yet been executed?
Trade events are generated by the server in the following cases
I suspect that OrderTotal() fails. But I can't prove it with this functionality.
Although as an option I don't reject that OrderTotal() is taking data not where I think it is (i.e. not on the server).
I am following this article. I would like to find out the answer to the question: how is it that a trade event misses the moment when an order has been placed but has not yet been executed?
By the time the Trade event arrives, the order has already been placed and executed. Therefore, this order hasn't yet been placed among the active ones and already appeared in the history.
Yes, yes, my thoughts are floating around this answer.
I would answer like this, at the time the order is placed, the server generates a "trades" event and sends it to the terminal, when the terminal receives it, a request is made in the code for the number of orders, but by the time this request comes to the server, the server has already executed the order.
I don't have any other explanation.
Trade events are generated by the server in the following cases:
I suspect that OrderTotal() fails. But I can't prove it with this functionality.
Did I understand correctly that the list of active orders includes both active pending orders and orders to open a position?
What does this mean?
... in "Experts" tab this message appears. It is not an error, it is a warning. A warning about what?
Well, I didn't say "mistake". Let it be a "warning". I've already said my version with an example. Have another look at the discussion from here (about line leakage - read to the end of the page): https://www.mql5.com/ru/forum/1111/page345#comment_54616
You may have to go to the BOD, with details of your situation.
Found a "confusion".
Why doesn't the compiler like the second b variable define?
And in general, how do I handle this situation?