The order must be previously selected by the OrderSelect() function
The OrderSelect() function copies order data into program environment and all further calls of OrderClosePrice(), OrderCloseTime(), OrderComment(), OrderCommission(), OrderExpiration(), OrderLots(), OrderMagicNumber(), OrderOpenPrice(), OrderOpenTime(), OrderPrint(), OrderProfit(), OrderStopLoss(), OrderSwap(), OrderSymbol(), OrderTakeProfit(), OrderTicket(), OrderType() functions return the data, copied earlier. It means that in some cases the order details (open price, SL/TP levels or expiration date) may change and the data become non-actual. It is strongly recommended to call the OrderSelect() function before request the order data.
Thanks for your speedy response. Great advice. I see in the orderselect section I have a piece of code that looks like :
//|---------close buy orders int CloseBuyOrders(int Magic) { int result,total=OrdersTotal(); for (int cnt=total-1;cnt>=0;cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderMagicNumber()==Magic&&OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),Bid,3); switch(OrderType()) { case OP_BUYLIMIT: case OP_BUYSTOP: result=OrderDelete(OrderTicket()); } } } } return(0);
I'll delete the "result=OrderDelete" bit.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
After recently joining and posting on the forums I was redirected to some excellent material which by and large helped me understand and make basic EA's. For the life of me though I can't understand why the close order portion of this EA isn't closing any positions. It is attached below.
Should I put something like this into it?
Any advice whether from someone or redirection to relevant material would be great.