Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 755
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
Hello. I can't figure out what is wrong.
There are two orders with smaller and larger volume and different take profit. The order with the smaller volume is opened first, then the order with the larger volume. We need to find a Take Profit for the order with larger volume.
Everything seems to be correct but for some reason, we get take profit values of the order with a smaller volume (it was opened first). What is wrong?
P.S. total = OrdersTotal()
Hello. I can't figure out what is wrong.
There are two orders with smaller and larger volume and different take profit. The order with the smaller volume is opened first, then the order with the larger volume. We need to find a Take Profit for the order with larger volume.
Everything seems to be correct but for some reason, we get take profit values of the order with a smaller volume (it was opened first). What is wrong?
P.S. Total = OrdersTotal()
It seems that the function MaxLotBuy() contains its own order search and another order appears to be selected when we return to this function. Avoid order rebound outside some order rebound cycle. I do not understand what I said. But it's true.
In this situation, we'd better declare a variable before the loop and assign to it the OrderLots() value provided that the new value is larger than the previous one.
The MaxLotBuy() function seems to have its own order loop and another order is selected when returning to this function. You should avoid going through the order outside of any order loop. I do not understand what I said. But it's true.
In this situation, we'd better declare a variable before the loop and assign it the OrderLots() value provided that the new value is larger than the previous one.
Thank you. Yes,MaxLotBuy() has its own enumeration of orders, but the return value is the maximal one (I'll give you the code).
But I have understood your idea, thanks. I will try it now.
That's probably the right way to go.
Thank you, that seems better.
I think the right thing to do would be
Thank you. It's not just when you write to yourself that you have to be careful.
Although that's what it says in words.
Guys, thank you very much; it works as it should. Just added a reset to the original position as well.
Guys, thank you very much; it works as it should. Just added a reset to the original position as well.
Well, yes. My example is not complete. I just corrected it, supplemented it and my correction coincided with your message in time.
It doesn't matter that it's not complete, what matters is the right idea, the right approach. Thank you all again.
It doesn't matter that it's not complete, what matters is the right idea, the right approach. Thank you all once again.
Then it goes like this
Then it looks like this
Basically I haven't posted all the code, but only a part of finding the take profit of the order with the highest lot. The whole point is as follows - when the price reverses, a pending order with a bigger lot is placed. If it works, a stop loss is set on the opposite order so that when the order with big lot is closed at Take Profit, the order with negative profit at stop loss is also closed. The full code of modification with setting a stop loss looks like this
P.S. During testing, there are so many nuances that need to be "explained" to the Expert Advisor as to how it should behave in certain cases.