In your example it doesn't matter. Both options are identical.
But the disadvantage of OrderClosePrice is that using OrderClosePrice requires that the order to be closed be previously selected using OrderSelect. If you start collecting information about orders into an array of structures/classes, then you will need to use bid/ask because the order being closed will not be preselected.
So I would suggest to always use bid/ask so that your code is the same regardless of whether an order is selected
Either works | ResetLastError(); if(OrderType() == OP_BUY) { if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, clrBlue)) Print(__FUNCTION__ " => Buy Order failed to close, error code:", GetLastError()); } else if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, clrYellow)) Print(__FUNCTION__ " => Sell Order failed to close, error code:", GetLastError()); } |
Simplified | ResetLastError(); if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, clrYellow)) Print(__FUNCTION__ " => " + string(OrderType()) + " Order failed to close, error code:", GetLastError()); } |
Another way to simplify (using bid/ask while doing this):
if(!OrderClose(OrderTicket(), OrderLots(), OrderType() == OP_BUY ? Bid : Ask, Slippage, clrYellow))
The code can be made even shorter:
if(!OrderClose(OrderTicket(), OrderLots(), OrderType() ? Ask : Bid, Slippage, clrYellow))
But I wouldn't do that😄
ternary operator works inside functions like OrderClose(), OrderModify(), OrderSend(), etc?
Why not? The ternary operator returns a value.
One confusion. My developer saying using OrderClosePrice() is wrong. It get the price of closed order but order is still open and not closed.
Using OrderClosePrice when closing an order is not wrong. And it works.
Above I described a couple of disadvantages of this method. But if you are sure that the desired order has been pre-selected, you can use OrderClosePrice.
Why not? The ternary operator returns a value.
This is correct
OrderSend(Symbol(), OP_SELL, Lot_Size, Bid, Slippage, SL = SL == 0 ? 0 : (Bid + SL * Point), TP = TP == 0 ? 0 : (Bid - TP * Point), SellStopTradeComment, gSellMagic, 0, clrYellow);
So, it always good to use Ask/Bid instead of OrderClosePrice()?
OrderSelect+OrderClosePrice.
Boyko, saying OrderClosePrice is not good approach.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Should i use Bid/Ask for closing trade
or OrderClosePrice() ?