Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1208

 
Vladpedro:

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:

  1. If we have only two positions, then we should look for the one that has more profit and close it.
  2. If we have more than two positions, if their total profit is more than the specified one, then we close all positions.
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Приказы на проведение торговых операций оформляются ордерами. Каждый ордер имеет множество свойств для чтения, информацию по ним можно получать с помощью функций Идентификатор позиции, который ставится на ордере при его исполнении. Каждый исполненный ордер порождает сделку, которая открывает новую или изменяет уже существующую позицию...
 
Vladimir Karputov:

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:

  1. We have only two positions - so we look for the one with more profit and close it.
  2. Have more than two positions - if their total profit more than the specified - close all positions

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.


 
Vladpedro:

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:

  1. We have only two positions - so we look for the one with the bigger profit and close it.
  2. If we have more than two positions, if their total profit is greater than the specified one, we close all positions.


Next please do something yourself.

 
Vladimir Karputov:

Sorry:

I showed an example solution for two cases:

  1. We have only two positions, so we look for the one with the highest profit and close it.
  2. We have more than two positions - if their total profit is higher than the given one, we close all positions.


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, not to multiply topics - my question is this - the script set a pending stop order with a well-defined take and stop, it is not executed, and in the comments is prescribed [illiquidity] - how to fight - to loop the script before execution, set a higher slippage, or prescribe the number of retries or what ? Or give me a hint where to dig.
 
neitrino22:
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

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Приказы на проведение торговых операций оформляются ордерами. Каждый ордер имеет множество свойств для чтения, информацию по ним можно получать с помощью функций Идентификатор позиции, который ставится на ордере при его исполнении. Каждый исполненный ордер порождает сделку, которая открывает новую или изменяет уже существующую позицию...
 
Alexey Viktorov:

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?

2020.04.27 15:19:08.415 Tester  XAUUSD: history data begins from 2014.02.12 00:00
2020.04.27 15:19:08.415 Tester  XAUUSD: history data begins from 2014.02.12 00:00
2020.04.27 15:19:08.415 Core 01 connecting to 127.0.0.1:3000
2020.04.27 15:19:08.415 Core 01 connected
2020.04.27 15:19:08.425 Core 01 authorized (agent build 2361)
2020.04.27 15:19:08.427 Tester  XAUUSD,M15 (Alpari-MT5-Demo): testing of Experts\ExpertTest.ex5 from 2017.07.26 00:00 to 2020.02.06 00:00
2020.04.27 15:19:08.466 Core 01 disconnected
2020.04.27 15:19:08.466 Core 01 connection closed

I delete all objects. I close files. Here is the log when I stop testing:

2020.04.27 15:15:43.188 Core 01 disconnected
2020.04.27 15:15:43.188 Core 01 connection closed
2020.04.27 15:15:43.189 Tester  stopped by user

Next time it won't start - I have to close terminal and open it again. Build 2361.

 
How can I get a closed position comment in OnTradeTransaction?