Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1208
![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
It makes no difference. I have a suspicion of a difference, because when I set orders and positions, I gave them "comments" for positions my own, for orders my own. As a result, when an order moves to a position, it inherits the comment of the order.
Then when we checked the positions through comments, there was a mess... the comments were different. I fixed that.
In your code, I haven't found or understood at all how the positions are closed for the condition SELL_LIMIT has triggered . Equity.
It seems that we have checked if all positions can be closed, and the flag is set for it
but in theCloseAllPositions();
there is something missing.
There is no check for closing all positions for the case - SELL_LIMIT has triggered.
Perhaps this samem_account.Equity()>= m_account.Balance()+15is implemented in some other way?
Or maybe it's because I've explained incorrectly what averaging means in my context.
I have already mentioned above - pending orders have nothing to do with it. A pending order cannot have a profit. From the word "at all". Until you make that clear, you can't move on.
Added: I've shown an example solution for two cases:
I have already pointed out above - pending orders have nothing to do with it at all. A pending order cannot have a profit. From the word "at all". Until you make this clear, you cannot move further.
Vladimir. Well, of course, a pending order cannot have profit. Of course, we are talking about the profit of the open positions.
Only the difference is in how these positions were opened. We need a different closing method for them.
If the second position is opened from a smart SELL_STOP order, then one of them must be closed, the one that has a larger profit of the position. This has worked out for you and works.
If the second position opened from an SELL_LIMIT order, then they should both be closed by Equity(m_account.Equity()>= m_account.Balance()+15) Unless the SL of one of them is triggered first.
Added.
I have shown an example solution for two cases:
Everything seems to be OK with the second condition. But for some reason I have the second condition opens the second position and closes it immediately close to 0 -1,2.
Maybe I specify total profit in a wrong place?
InpProfitTarget = 15; If here, it does not work.
Vladimir. Well of course a pending order cannot have a profit. We are talking about profits of course about open positions.
Only there is a difference in how these positions were opened. We need a different closing method for them.
If the second position is opened from a smart SELL_STOP order, then one of them must be closed, the one that has a larger profit of the position. This has worked out for you and works.
If the second position opened from an SELL_LIMIT order, then they should both be closed by Equity(m_account.Equity()>= m_account.Balance()+15) Unless the SL of one of them is triggered first.
Sorry:
I showed an example solution for two cases:
Next please do something yourself.
Sorry:
I showed an example solution for two cases:
From here, please do something yourself.
Thank you for your help Vladimir, I am trying.
2. we have more than two positions - if their total profit is greater than the specified one, we close all positions.
But I didn't need it, I needed two or more positions where the second one was opened withSELL_LIMIT triggering.
Thanks anyway for your patience and efforts. Of course, I'll solve it in my own way, I'll suffer and solve it)))
Good evening guys, so as not to multiply the threads, here's a question - the script put a pending stop order with quite a specific take and stop, it is not executed, and in the comments is written [illiquidity] - how to deal with it - loop the script before execution, set higher slippage, or specify the number of retakes or what ? Or give me a hint where to dig.
You should always look in the documentation
ORDER_TIME_GTC
The order will remain in the queue until it is withdrawn
You should always look in the documentation
ORDER_TIME_GTC
The order will remain in the queue until it is withdrawn
Thank you, that must be it
Good evening!
There is 1 open position.
The Expert Advisor closes a position using the PositionClose() method;
The result is printed ResultRetcode= 10009. Code description: done at 0.00
Below the code, there is a check if(PositionSelect(_Symbol)), which succeeds.
I.e., some time passes between the execution of PositionClose() and disappearance of the open position, during which the program manages to make a wrong exit.
How to solve this situation correctly?
Why do I have to restart the terminal every time after a test to run a new test?
I delete all objects. I close files. Here is the log when I stop testing:
Next time it won't start - I have to close terminal and open it again. Build 2361.