Check the returned value of the OrderSend function
- docs.mql4.com
If it failed to open a new position, when and how could I know?
- On a dealing desk broker it would be Ask ± 3 × Points. On ECN brokers the spread is ignored.
-
Check your return codes for errors, and report them including GLE/LE, your variable values, and the market. That way we would know that at least you are calling your code.
What are Function return values ? How do I use them ? - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Hi, I am a beginner in writing EAs with MQL4 and I encountered a question that confused me. If I send an order of AUDUSD pair like the following:
OrderSend(Symbol(), OP_BUY, NormalizeDouble(lot_size, Digits), Ask, 3, 0, 0, "LONG", MAGICMA, 0, Green);
How could I know whether the market order has been successfully executed or not?
If the position is successfully opened, would the price be between Ask - 3 and Ask +3?
If it failed to open a new position, when and how could I know?
It will be super helpful for me if somebody could answer these questions clearly, since my algorithm needs to monitor the state of the order to decide what to do next.
int ticket=0; ticket=OrderSend(Symbol(), OP_BUY, NormalizeDouble(lot_size, Digits), Ask, 3, 0, 0, "LONG", MAGICMA, 0, Green); if(ticket<1) { Print("Order send error BUY order, errcode : ",GetLastError());// Fetch error code here and print the reason return; // in experts journal. } else Print("Order BUY sent successfully");// If order successfully sent, print it in experts journal
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I am a beginner in writing EAs with MQL4 and I encountered a question that confused me. If I send an order of AUDUSD pair like the following:
OrderSend(Symbol(), OP_BUY, NormalizeDouble(lot_size, Digits), Ask, 3, 0, 0, "LONG", MAGICMA, 0, Green);
How could I know whether the market order has been successfully executed or not?
If the position is successfully opened, would the price be between Ask - 3 and Ask +3?
If it failed to open a new position, when and how could I know?
It will be super helpful for me if somebody could answer these questions clearly, since my algorithm needs to monitor the state of the order to decide what to do next.