-
int Ticket=OrderTicket(); double lots=OrderLots(); string symbol=OrderSymbol(); if(OrderSelect(Ticket,SELECT_BY_TICKET))
You can not use any Trade Functions until you first select an order.
-
You can use OrderClosePrice() instead of Bid/Ask and be direction independent — no need to check order type for close price.
-
You are looping over position index. That is not a ticket. Select by position.
- All orders selected by position will have OrderCloseTime of zero, by definition.
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CloseAllOrders() { for(int pos=OrdersTotal()-1; pos>=0; pos--) { int Ticket=OrderTicket(); double lots=OrderLots(); string symbol=OrderSymbol(); if(OrderSelect(Ticket,SELECT_BY_TICKET)) { if(OrderCloseTime()==0) { if(OrderType()< 2) { // Close open orders if(OrderClose(Ticket,lots,OrderClosePrice(),9999,Red)) Print("Sell order closed. Ticket=",Ticket,", symbol=",symbol,", Lots=",lots); else Print("Error in closing sell order: Error code=",GetLastError(),". Ticket=",Ticket,", symbol=",symbol,", Lots=",lots); } else { // Delete pending orders if(OrderDelete(Ticket,CLR_NONE)) Print("Pending order deleted. Ticket=",Ticket,", symbol=",symbol,", Lots=",lots); else Print("Error in deleting pending order: Error code=",GetLastError(),". Ticket=",Ticket,", symbol=",symbol,", Lots=",lots); } } } } } //+------------------------------------------------------------------+
-
You can not use any Trade Functions until you first select an order.
-
You can use OrderClosePrice() instead of Bid/Ask and be direction independent — no need to check order type for close price.
-
You are looping over position index. That is not a ticket. Select by position.
- All orders selected by position will have OrderCloseTime of zero, by definition.
-
You can not use any Trade Functions until you first select an order.
-
You can use OrderClosePrice() instead of Bid/Ask and be direction independent — no need to check order type for close price.
-
You are looping over position index. That is not a ticket. Select by position.
- All orders selected by position will have OrderCloseTime of zero, by definition.
I get that.
I will try them again.
Thank you for the help.
Hey. Raymond.
How are you doing?
Thank you for reply.
I will correct them.
:)
Hey. Raymond.
How are you doing?
Thank you for reply.
I will correct them.
:)
Hey i am doing well, you are welcome
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear
I have no idea why it does not delete pending orders after closing positions.
It close open position in perfect way.
Somehow, it does not delete pendings.
Any help?