![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
Hi, I think the problem is caused by the long processing time of trade server.
if trade condition is satisfied, buy or sell order was sent to the trade server. When your EA gets true from the server, it does not mean the success creation of position. It only means your order was accepted and waiting for further process. So for these codes to modify the position:
// set stoploss and takeprofit
double sl=0,tp=0;
if(PositionsCounter()==1)
they are immediately executed just after the sending of order. At this time, the position may be not created by the server. the result of executing " if(PositionsCounter()==1) " may be false. At this situation, the position modification should be executed during the coming of next tick if position was created by the server then.
The worst situation is that when the next tick comes, the server does not create the position. Just here your EA send one more order you don't wish.
If we are using OrderSendAsync then there is no way of telling whether position is opened or not. However since user greenteen and his code above was sending order using CTrade Class which using OrderSend, then we could easily tell whether the position is opened or not by simply checking OrderSend result and return code.
Hello, I am afraid that the return value of OrderSend does not indicate a sign of successful execution of a trade operation.
https://www.mql5.com/en/docs/trading/ordersend
Return Value
In case of a successful basic check of structures (index checking) returns true. However, this is not a sign of successful execution of a trade operation. For a more detailed description of the function execution result, analyze the fields of result structure.
I also have a new question, I found the magic of a deal is not same as EA's magic (3344), although this deal is opened by EA.
I use the below code to check the magic of a deal in History tab, but it show 0 instead of 3344
Hello, I am afraid that the return value of OrderSend does not indicate a sign of successful execution of a trade operation.
...
That is true, however this is what I said (see the yellow highlighted word :)
phi.nuts:
...then we could easily tell whether the position is opened or not by simply checking OrderSend result and return code.
I also have a new question, I found the magic of a deal is not same as EA's magic (3344), although this deal is opened by EA.
I use the below code to check the magic of a deal in History tab, but it show 0 instead of 3344
Did you check in the mql5 documentation what DEAL_MAGIC is ?, I haven't check but I think that's for pending orders.
That is true, however this is what I said (see the yellow highlighted word :)
Did you check in the mql5 documentation what DEAL_MAGIC is ?, I haven't check but I think that's for pending orders.
Hello Phi,
DEAL_MAGIC is for deals not for pending orders