- You must call OrderSelect() before you call OrderClose() or any other OrderXXX() function. Otherwise, result of the OrderClose() and other functions is undefined.
- OrderClose() returns boolean which indicates if an order is closed or not. It definitely does not return ticket number.
- Use OrderClosePrice() instead of Bid and Ask. It automatically knows which price to use depending on order type - buy or sell.
- How is variable "Slippage" defined in your code? What's its value?
//Simplified example if(OrderSelect(idx, SELECT_BY_POS)) { if(OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red)) return(0); else // Order not closed, do error handling and recovery here Print("OrderClose() returned the error of ",GetLastError()); }
Drazen Penic:
- You must call OrderSelect() before you call OrderClose() or any other OrderXXX() function. Otherwise, result of the OrderClose() and other functions is undefined.
- OrderClose() returns boolean which indicates if an order is closed or not. It definitely does not return ticket number.
- Use OrderClosePrice() instead of Bid and Ask. It automatically knows which price to use depending on order type - buy or sell.
- How is variable "Slippage" defined in your code? What's its value?
Thanks Drazen for the information.
Still trying to make it work :)
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,
Trying to understand why I got the OrderClose error 4051 (invalid ticket for OrderClose function).
I did read all the documentation I could find on google searching for the error code.
Also read https://www.mql5.com/en/forum/139592 .
But because I am writing my first EA I don't fully understand all the information provided.
Please see the code:
Fixed_Target_Long = I just set it at 50 pips to try it out.
Appreciate all the help!!
Dave