To close orders use OrderClosePrice () function instead of Bid or Ask or any other price.
Example: "OrderClose ( OrderTicket (), OrderLots (), OrderClosePrice (), 0 ) ;"
leyou1233:
First sum the profit, then close allif buy Profit + sell Profit>0;
I want to close the buy ticket and the sell ticket, the lots is difficult. but it is error. how to slove it ?
double total=0; for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderType() <= OP_SELL ){ // open orders only, && OrderSymbol() == Symbol() // and my pair. total += OrderProfit(); } if (total > 0) for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() ){ // and my pair. if (!OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), Slippage.Pips*pips2points, CLR_NONE) )) Alert( "OrderClose(ticket=", OrderTicket(), ", ...) failed: ", GetLastError()); }

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
if buy Profit + sell Profit>0;
I want to close the buy ticket and the sell ticket, the lots is difficult. but it is error. how to slove it ?