Features of the mql5 language, subtleties and tricks - page 70
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
Forum on trading, automated trading systems and trading strategies testing
How do I identify a chart replacement?
fxsaber, 2018.02.08 12:39
Zero ChartID input parameter in some functions does not cause recalculation of values. If you want actual data of the current chart, you need to use the full ID.
Forum on trading, automated trading systems and testing trading strategies
POSITION_TICKET != POSITION_IDENTIFIER
fxsaber, 2018.02.12 20:14
Conclusions
If we assume that this is normal behavior of MT5, and not the peculiarities of the broker's hack, then
Disadvantages
ZZY Completely confirmed hypothesis.
Forum on trading, automated trading systems and testing trading strategies
POSITION_TICKET != POSITION_IDENTIFIER
Pavel Kolchin, 2018.02.12 13:31
(I'm not sure, it's hard to check, by analogy with partial position closing)
It all works like this:
1) pending order triggered partially - position with Position_ID = Order_Ticket1 is opened
2) the rest of the order is formed into a new order Order_Ticket2 and is waiting for its fulfillment, the new Order_Ticket2 != Order_Ticket1 since there cannot be two orders in the history with the same Order_Ticket
3) the remaining order is executed - the position with Position_ID = Order_Ticket2 is opened
there are two orders in the history, two positions in the terminal, everything corresponds
Forum on trading, automated trading systems and testing trading strategies
Discussion on "LifeHack for trader: mixing ForEach on defines (#define)"
fxsaber, 2018.02.14 10:54
Performance measurement
Result
I was totally wrong! SymbolInfoDouble is twice as slow as SymbolInfoTick.
Forum on trading, automated trading systems and trading strategy testing
Discussion on "LifeHack for trader: mixing ForEach on defines (#define)"
fxsaber, 2018.02.14 11:58
Incompetent. Result in Tester.
Where performance is needed (Optimizer), it is better to use SymbolInfoDouble. On the real, it makes no difference.
ZZY Function speed measurements should be measured in an environment where performance is important - Tester.
Forum on trading, automated trading systems and trading strategies testing
Bugs, bugs, questions
fxsaber, 2018.02.12 23:10
Opening BUY position by hand on two trading demo servers
RoboForex-MetaTrader 5
FXOpen-MT5.
The lines of the same color indicate the same thing. However, it's clearly seen that they are in different sequence. For Robo, the message about order execution comes after the trade execution. With open, it comes BEFORE! For this reason OrderSend returns luck, but no deal yet. I.e. we get unsynchronized OrderSend with the history
The code for FXOpen-MT5
Result
This situation has the following explanation
Forum on trading, automated trading systems and strategy testing
Bugs, bugs, questions
Rashid Umarov, 2018.02.15 06:25
If an order is sent to an external trading system, the MetaTrader 5 trading server does not wait for a response from it and immediately returns the result of the request as "order placed". For this reason, OrderSend will always return deal=0, as there is no information about the executed deal yet. Catch it in OnTrade or OnTradeTransaction.
An example of trade event listener is given in the article What to start with when creating a trading robot for MO EX - TradeTransactionListener.mq5
OrderSend - sends an order to execute a market trade.The order is placed- for that you need to read Result.order. But no one waits for the deal(s) - there may be a lot of them and the total time of their execution is not defined.
It depends on the specific implementation of the output on the broker's side. In the general case it is not defined.
So, I highly recommend to use the demo account on FXOpen-MT5 as a test for your code, because it is quite a different one compared to other demos.
For example, I suggest to try writing a script in MQL5 with such trading logic (MQL4-style is only for quick sense display)
It is not easy at all. I also recommend to try the mentioned demo server to work on partial execution.
Deleted a post that explained one of the most common mistakes on MT5.
The post was a big one. Didn't expect to be deleted. I'd like to hear the reason for deletion. Because getting deleted again is masochistic.
Forum on trading, automated trading systems and trading strategies testing
Organizing an order loop
fxsaber, 2018.02.16 09:40
Everything is not okay at all in MT5. Example showing the problem.
What do you think, if you run this script on a symbol with no positions, what will happen in the end?
The correct answer is that one or two positions will be opened.
The reason why this happens. After the first OrderSend, a market order appears, and if a new tick comes before the moment of its execution, there is no position yet, so the second OrderSend is made.
Because of this, a seemingly normal MT5 pattern willnot work properly and, as a consequence, most of the MT5 Expert Advisors in codobase. In this case, an almost identical MT4-template will continue to work without any problems.
The idea of PositionsTotal, not bad at first glance, is somewhat overshadowed by the need in MT5 to also analyze OrdersTotal for market orders.
Be careful!
Because of this, a seemingly normal MT5 pattern willnot work properly and, as a consequence, most MT5 EAs in kodobase.
As a proof of this statement we can take almost any Expert Advisor from MT5 kodobase. We will not go fishing for something, but we will take the most recent Expert Advisor at the moment. It is good that it was written by an author with a large MT5-experience of publications in QB.
The source code has the following strings (my comments are highlighted)
We have an identical situation to the one described above.
Forum on trading, automated trading systems and testing trading strategies
Peculiarities of mql5 language, tips and tricks
fxsaber, 2018.02.16 19:52
After the first OrderSend a market order appears and if a new tick comes before its execution, there is no position yet and the second OrderSend is made.
The idea of PositionsTotal, which is not bad at first sight, is somewhat overshadowed by the necessity to analyze OrdersTotal for market orders in MT5.
It means that in the general case, the EA will open two, three, etc., instead of one position. Depending on how often ticks come and how long market orders are executed.
Since almost all MT5 EAs in kodobase are written with the same logic as the MT5 template, they also have the same bug that is contained in it. This is true of almost all MT5-advisors in KB, unfortunately.
On a netting there may be an open position and several market orders of any direction on the same symbol at the same time. For example, a BUY position and a BUY order. True, I have not managed to find such a demo account, because there was a rule with asynchrony everywhere
Forum on trading, automated trading systems and trading strategies testing
Bugs, bugs, questions
fxsaber, 2018.02.14 08:58
The entire OnTradeTransaction event sequence comes after the OrderSend is completed.
EA
Sending trade order by hand.
Log
2018.02.14 09:41:46.671 '8854170': instant sell 1.00 EURUSD at 1.23673 2018.02.14 09:41:46.853 '8854170': accepted instant sell 1.00 EURUSD at 1.23673 2018.02.14 09:41:46.853 '8854170': deal #192088422 sell 1.00 EURUSD at 1.23673 done (based on order #208541700) 2018.02.14 09:41:46.853 '8854170': order #208541700 sell 1.00 / 1.00 EURUSD at 1.23673 done in 190.608 ms
Result of Expert Advisor
We can perfectly see from the time column and the numeric values of the EA that the duration of trade order execution has no effect on the sequence of OnTradeTransaction events. All the asynchrony goes to hell! They have managed to screw it up so badly. Build 1755.
For example, when OrderSendAsync market order is placed in the Terminal, the market order doesn't even appear for a moment. Perhaps the developers decided to do this to speed things up a bit.
Forum on trading, automated trading systems and trading strategies testing
Discussion of the article "Visualizing trade strategy optimization in MetaTrader 5"
fxsaber, 2018.02.22 08:39
In frame mode, OnInit, OnDeinit, OnTick, OnTrade, OnTradeTransaction and OnTimer are ignored. Only OnChartEvent works.
Of course, because of the OnChartEvent exception it requires a mandatory check for the frame mode flag.