Incorporate this function in your code and call it with the close position .
Im assuming you are in absolute control of the trades that occur in the account , or you are certain your users will be in (referring to selecting by position 0 always)
Here is the close function :
//assuming you are in control of the positions and what is traded in your ea : bool CloseOrder(int position, int attempts, uint timeout, int slippage, bool refresh_needed) { bool result=false; int attempted=0; double cp=0; color clr=clrBlue; bool findit=OrderSelect(position,SELECT_BY_POS,MODE_TRADES); //if position selected if(findit) { int ticket=OrderTicket(); int type=OrderType(); double lots=OrderLots(); //attempts loop while(!result&&attempted<=attempts) { attempted++; if(refresh_needed){RefreshRates();} if(type==OP_BUY){cp=Bid;} if(type==OP_SELL){cp=Ask;clr=clrRed;} result=OrderClose(ticket,lots,cp,slippage,clr); //if succesful or not and more attempts delay if(result||(!result&&attempted<attempts)){Sleep(timeout);} } //attempts loop ends here } //if position selected ends here return(result); }
Lorentzos Roussos:
Thank you so much sir.
Incorporate this function in your code and call it with the close position .
Im assuming you are in absolute control of the trades that occur in the account , or you are certain your users will be in (referring to selecting by position 0 always)
Here is the close function :

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
Hello
These codes consist of two keys, the first key closes half of the first open trade and the second key closes completely.
The keys work in the demo account but do not work in the real account.
Please help me, What's problem?!