Questions from Beginners MQL5 MT5 MetaTrader 5 - page 815

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
I just can't figure out if it's normal that .
There are a lot of things that are difficult to understand here. In particular, when dealing with the sequence of transactions, I have found that there are some inconsistencies in a number of cases.
In my opinion, it is best to organise your trade control: remember your trade orders and monitor the composition of orders and positions simply by the fact of their presence in the relevant lists.For example, when a position is opened, a market order is formally opened first, which then turns into a position. However, during this machine-gun series of transactions there is a situation where a position has already been opened, but the order has not yet been closed. Clearly this is the same event, but the transactions are organised piecemeal, issued sequentially, and with this approach it is in principle impossible to correctly reflect the transformation of a market order into a position.
Speaking of birds.
Did you know that market orders are issued in these transactions with a zero price?
For example, a person wants to open a Buy position at 1.2000, Sl=1.1000, Tr=1.3000.
When this transaction is executed, the first thing the transaction appears where the market order is listed with the following data:
Sl= 1.1000, Tr= 1.3000, i.e. with the specified numbers and Price=0 (equal to zero). Just a kind of market order with zero price :) And think what you want.
For convenience. A small function is called from MqlTradeTransaction. The required element is found there through searching for elements of the class. And for this element, one of the class functions is called which does something useful.
Please describe in more detail what exactly you want to get? Why do you call something from OnTradeTransaction?
First just in words, then we'll correct it in the right direction.
The user's function Abc() is executed, and it implements a long (in terms of time) algorithm.
During the execution of this function, some events take place, for example - Trade, Timer, etc.
Is it possible to know that these events occurred without finishing execution of the Abc() function?
No. While one function is counting, everything else will be skipped.
It is similar totheSleep()function- i.e. while your function is counting for a very long time, its behavior is similar to Sleep - all the other events will be skipped.
...
Absolutely everything is transparent in OnTradeTransaction.
First:MqlTradeTransaction structure is filled differently depending on trade transaction type (ENUM_TRADE_TRANSACTION_TYPE).
read here:Structure of a Trade Transaction (MqlTradeTransaction)
Second: To visualize results, we can extract this code block fromOrderSendAsync example
and paste it into an Expert Advisor that can be attached to a chart. Then you can manually open/close positions and look at printout of results in Experts tab.
No. While one function is counting, everything else will be skipped.
It is analogous totheSleep()function- that is, while your function is counting for a very long time, its behavior is anflogical to Sleep - all the rest events will be skipped.
Thank you, that's unfortunate.
And how to use the PC resource effectively then? Again looped code and periodical polling of parameters?
Absolutely everything is transparent in OnTradeTransaction.
Thanks for the reply, that's pretty much what I did. More questions than insights so far...
Please describe in more detail what exactly you want to get? Why do you call something from OnTradeTransaction?
First just in words, then we'll correct it in the right direction.
I understood that the problem is not with OnTradeTransaction. Look what a mess I've got here:
Here is the code.
And here is the result of its execution
2017.09.22 10:30:12 Failed to select position by symbol SBRF-12.17
2017.09.22 10:30:12 Volume 0.0 Volume 0. 0
I swap lines 2 and 3. i.e. the code is now
I get a result like this.
2017.09.22 10:30:12 Failed to select position by symbol SBRF-12.17
2017.09.22 10:30:12 SBRF-3.18 Volume 1.0 SBRF-3.18 Volume 1.0
In both cases no warnings are generated by the compiler. Attached is the 80 line Expert Advisor code and testing settings. Broker BCS. The version 1730.
I realised that the problem is not with OnTradeTransaction. Look what a mess I've got going on:
Here's the code.
And here is the result of its execution
2017.09.22 10:30:12 Failed to select position by symbol SBRF-12.17
2017.09.22 10:30:12 Volume 0.0 Volume 0.0
I swap lines 2 and 3. i.e. the code is now
I get a result like this.
2017.09.22 10:30:12 Failed to select position by symbol SBRF-12.17
2017.09.22 10:30:12 SBRF-3.18 Volume 1.0 SBRF-3.18 Volume 1.0
In both cases no warnings are generated by the compiler. Attached is the 80 line Expert Advisor code and testing settings. Broker BCS. The version 1730.
The error seems to be in trying to get information about more than 1 position, in 1 line(Print).
Only information about 1 (selected ) position is available at any time :
- In the second case it is correct, because last Select returns true , which you have not checked.
- And in the first case : last Select returns false , which you also didn't check, and the result is unpredictable.
..... obviously Select==false resets the information of the previous Select==true