orderclose is enough if you know the ticket number.
orderclose is enough if you know the ticket number.
Thank you
Hello freinds,
I have a tecnical quastion:
If I want to close an open trade, and I already know its: Ticket number, lot size and the correct price.
If you use OrderClosePrice() you don't even have to distinguish between Buys and Sells.
If you have the ticket number, OrderClose() is enough.
If ALL you have is the ticket number, then you must check to see if the ticket is still open (or handle the error if it has already closed) OrderSelect() and test if OrderCloseTime() is still zero.
If you don't want to distinguish between Buys and Sells you can use OrderClosePrice() but then you must OrderSelect() before using it
Hello freinds,
I have a tecnical quastion:
If I want to close an open trade, and I already know its: Ticket number, lot size and the correct price. Do
I have to preceed the ORDERCLOSE() with ORDERSELECT()?
Thank you all,
Y.
Use the following code:
// in case if position is BUY - Bid, if SELL - Ask int ticket=12345678; // ticket's number OrderClose(ticket, OrderLots(), Bid, 3, CLR_NONE);
Use the following code:
And don't forget the OrderSelect() if you want to use OrderLots() ;-)
And don't forget the OrderSelect() if you want to use OrderLots() ;-)
Hmm, in my EA I close positions always with OrderSelect()... and then OrderLots() inside of OrderClose(). I thought that OrderLots() works correctly without OrderSelect(). So, the correct code is:
// in case if position is BUY - Bid, if SELL - Ask int ticket=12345678; // ticket's number double my_lot=0,1: OrderClose(ticket, my_lot, Bid, 3, CLR_NONE);
Hmm, in my EA I close positions always with OrderSelect()... and then OrderLots() inside of OrderClose(). I thought that OrderLots() works correctly without OrderSelect(). So, the correct code is:
You are not handle a 5 digit situation if you simply use 3 for Slippage
Don't forget freezelevel if the price is almost at OrderStopLoss() or OrderTakeProfit() it can fail
Instead of Bid or Ask to close a trade you can simply use OrderClosePrice() see Comment of RaptorUK
in your example is also not checked if the trade is still open see comment WHRoeder also
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello freinds,
I have a tecnical quastion:
If I want to close an open trade, and I already know its: Ticket number, lot size and the correct price. Do
I have to preceed the ORDERCLOSE() with ORDERSELECT()?
Thank you all,
Y.