Discussion of article "Library for easy and quick development of MetaTrader programs (part VIII): Order and position modification events" - page 3
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
When a tick is received, on which a pending order is set and simultaneously activated (triggered) (I tested with Buy Stop), your engine does not register all events...
The TRADE_EVENT_PENDING_ORDER_PLASED event is received, but not TRADE_EVENT_PENDING_ORDER_ACTIVATED.
My code is something like this:
I first find the index of the old (processed) event in the loop, and then starting from it, I loop through all the new ones until the end. So, in a situation where on one tick a limit order is set and striggeren receives one event about setting... Please comment.
I call ProcessTradeEvents() in OnTick() after engine.OnTick(rates_data).The order was placed by your engine. Maybe I still called it when there was no activation yet..... I'll check it with a manual order now.
The order was placed by your own engine. Maybe I still called it when there was no activation yet..... I'll check with a manual order now.
Yes, I think it's my hands that are crooked....
Yeah, I think my hands are crooked...
Hello.
I encountered this problem while testing TestDoEasyPart08.mq5 - StopLoss and TakeProfit do not work. Although they are set - the corresponding lines appear on the chart, and messages to the journal come. If you switch on TrailStop, TakeProfit triggers, but StopLoss still does not. What can be the reason?
P.S. I run the same code on another computer (laptop) and it works fine. Although the same metatrader is installed there.
Hello.
I encountered this problem while testing TestDoEasyPart08.mq5 - StopLoss and TakeProfit do not work. Although they are set - the corresponding lines appear on the chart, and messages to the journal come. If you switch on TrailStop, TakeProfit triggers, but StopLoss still does not. What can be the reason?
P.S. I run the same code on another computer (laptop) and it works fine. Although the same metatrader is installed there.
Good evening! First of all, please show at least the messages that appear in the log.
Regards, Vladimir.
Hello.
I encountered this problem while testing TestDoEasyPart08.mq5 - StopLoss and TakeProfit do not work. Although they are set - the corresponding lines appear on the chart, and messages to the journal come. If you switch on TrailStop, TakeProfit triggers, but StopLoss still does not. What can be the reason?
P.S. I run the same code on another computer (laptop) and it works fine. Although the same metatrader is installed there.
If stop (limit) orders are placed, their triggering depends not on the programme, but on the broker. The order to place stop (limit) orders is sent to the server by the programme, and their triggering depends on the broker. Since they are placed (their lines are displayed on the chart), there are no errors on the part of the programme. Most likely, the price does not reach the stop (limit) orders.
Good evening, at least show the messages that are logged.
Regards, Vladimir.
MrBrooklin, Artem.
I did it in the strategy tester (as I understand, the broker has nothing to do with it).
The messages are as follows:
2022.07.03 11:16:39.380 2022.01.03 07:00:00 instant buy 0.1 @Si at 81011 sl: 80960 tp: 81060 (81010 / 81011 / 81010)
2022.07.03 11:16:39.380 2022.01.03 07:00:00 deal #2 buy 0.1 @Si at 81011 done (based on order #2)
2022.07.03 11:16:39.380 2022.01.03 07:00:00 deal performed [#2 buy 0.1 @Si at 81011]
2022.07.03 11:16:39.380 2022.01.03 07:00:00 order performed buy 0.1 at 81011 [#2 buy 0.1 @Si at 81011]
But on another computer (laptop), on which StopLoss and TakeProfit work correctly, the messages are like this:
2022.07.03 11:23:18.383 2022.01.03 07:00:12 instant buy 0.1 @Si at 81047 sl: 80996 tp: 81096 (81046 / 81047 / 81046)
2022.07.03 11:23:18.383 2022.01.03 07:00:12 deal #2 buy 0.1 @Si at 81047 done (based on order #2)
2022.07.03 11:23:18.383 2022.01.03 07:00:12 deal performed [#2 buy 0.1 @Si at 81047]
2022.07.03 11:23:18.383 2022.01.03 07:00:12 order executed buy 0.1 at 81047 [#2 buy 0.1 @Si at 81047]
2022.07.03 11:23:18.514 2022.01.03 07:00:12 - Position open: 2022.01.03 07.03 07:00:12.490 -
2022.07.03 11:23:18.514 2022.01.03 07:00:12 @Si Opened 0.10 Buy #2 [0.10 Market order Buy #2] at 81047, sl 80996, tp 81096, magik 123
Indeed, two lines more...
To simplify things a bit, I wrote an Expert Advisor with this simple code:
The point is that when you press (or rather, when you release) the "Z" key, it opens Buy, and when you press the "A" key, it opens Sell.
I ran it in the tester. The result is the same - on a desktop PC StopLoss and TakeProfit do not work, but on a laptop they do, i.e. everything works correctly.
I also tried running the code linked to at the end of this article on both PC and laptop in the tester, and the same thing happened - on PC it doesn't work, but on laptop it works.
So the conclusion is that either there is some setting in the tester that allows triggering sl and tp (which I don't know about), or the tester itself is not working correctly....
MrBrooklin, Artem.
I did it in the strategy tester (as I understand, the broker has nothing to do with it).
The messages are as follows:
2022.07.03 11:16:39.380 2022.01.03 07:00:00 instant buy 0.1 @Si at 81011 sl: 80960 tp: 81060 (81010 / 81011 / 81010)
2022.07.03 11:16:39.380 2022.01.03 07:00:00 deal #2 buy 0.1 @Si at 81011 done (based on order #2)
2022.07.03 11:16:39.380 2022.01.03 07:00:00 deal performed [#2 buy 0.1 @Si at 81011]
2022.07.03 11:16:39.380 2022.01.03 07:00:00 order performed buy 0.1 at 81011 [#2 buy 0.1 @Si at 81011]
But on another computer (laptop), on which StopLoss and TakeProfit work correctly, the messages are as follows:
2022.07.03 11:23:18.383 2022.01.03 07:00:12 instant buy 0.1 @Si at 81047 sl: 80996 tp: 81096 (81046 / 81047 / 81046)
2022.07.03 11:23:18.383 2022.01.03 07:00:12 deal #2 buy 0.1 @Si at 81047 done (based on order #2)
2022.07.03 11:23:18.383 2022.01.03 07:00:12 deal performed [#2 buy 0.1 @Si at 81047]
2022.07.03 11:23:18.383 2022.01.03 07:00:12 order executed buy 0.1 at 81047 [#2 buy 0.1 @Si at 81047]
2022.07.03 11:23:18.514 2022.01.03 07:00:12 - Position open: 2022.01.03 07:00:12.490 -
2022.07.03 11:23:18.514 2022.01.03 07:00:12 @Si Open 0.10 Buy #2 [0.10 Market order Buy #2] at 81047, sl 80996, tp 81096, magik 123
Indeed, two lines more...
To simplify things a bit, I wrote an Expert Advisor with this simple code:
The point is that when you press (or rather, when you release) the "Z" key, it opens Buy, and when you press the "A" key, it opens Sell.
I ran it in the tester. The result is the same - on a desktop PC StopLoss and TakeProfit do not work, but on a laptop they do, i.e. everything works correctly.
I also tried running the code linked at the end of this article on both PC and laptop in the tester, and the same thing happened - on PC it doesn't work, but on laptop it works.
So the conclusion is that either there is some setting in the tester that allows triggering sl and tp (which I don't know about), or the tester itself works incorrectly....
The spread in the tester is 1. Both on PC and laptop. Symbol @Si.
Is there any way it can affect it?
I thought that maybe slippage (slippage) affects somehow and tried to change it. But it doesn't work.
The spread in the tester is 1. Both on PC and laptop. Symbol @Si.
Can this have any effect?
I thought maybe the slippage (slippage) was affecting it somehow and tried changing it. But it doesn't work.
In one of the cases, the price does not reach the stop level.