For a start you should use
if ( OrderType() == OP_SELL && OrderCloseTime()==0){
to prevent trying to close an order that is already closed
if (!OrderClose(ticketSell,OrderLots(),OrderClosePrice(),0,clrCoral)) { // Chiusura ordine SELL
Use OrderClosePrice() instead of Ask as it will be current from the OrderSelect()
but I have errors 138 and 4108
When asking for help please look up and post what the error return codes mean. That way everybody who reads your post does not have to look them up.

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
I want to close SELL order after a BUY order is opened.
I wrote this code but I have errors 138 and 4108, how can I fix it?
ps: the orders are generated by SELL LIMIT and BUY LIMIT functions