Rosh: I repeat you again: you open new position when you call CloseAll(). It is your error in your code.
I call CLoseAll() to close position not to open new position. call OpenOrder() to open new position. You can read the code. I first call CloseAll() ,then call OpenOrder(). Please notice the sequence.
xywen: I call CloseAll() is to close position ,not to create new position. You say call CloseAll() is to open new positon, Can you give a explain?
I have already explained that
Rosh:
It
is mistake. PositionSelect can return true if the client terminal
didn't get yet information from trade server. In this case your EA will
send new trade request to trade and open a new position without SL and
TP because I see this in your code:
I think the function OrderSend() will wait until the serve return information. it is impossible the program excute orderSend() and then excute next instruction without waiting for the server's information. otherwise the program don't know the result of excuting ordersend(), in the case,if the program excute next instruction, it will be uncontroled.
xywen: I think the function OrderSend() will wait until the serve return information.
No, it isn't. The trade functions are asynchronous. You don't need to wait for result of your trade request from OrderSend().
At the moment of the order processing, the trade server sends to the terminal a message about the occurrence of the Trade event, which can be processed by the OnTrade() function.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I repeat you again: you open new position when you call CloseAll(). It is your error in your code.
I repeat you again: you open new position when you call CloseAll(). It is your error in your code.
I call CloseAll() is to close position ,not to create new position. You say call CloseAll() is to open new positon, Can you give a explain?
I have already explained that
It is mistake. PositionSelect can return true if the client terminal didn't get yet information from trade server. In this case your EA will send new trade request to trade and open a new position without SL and TP because I see this in your code:
...
Read the article Trade Events in MetaTrader 5.
I have already explained that
I think the function OrderSend() will wait until the serve return information.
No, it isn't. The trade functions are asynchronous. You don't need to wait for result of your trade request from OrderSend().
At the moment of the order processing, the trade server sends to the terminal a message about the occurrence of the Trade event, which can be processed by the OnTrade() function.