bool result;
double price;
int error;
//----
int total = OrdersTotal();
for (int i = total - 1; i >= 0; i --)
{
// if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
if(OrderSelect(i,SELECT_BY_POS)==true)
{
result=false;
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
{
while(!result)
{
if(OrderType()==OP_BUY) price=Bid;
else price=Ask;
result=OrderClose(OrderTicket(),OrderLots(),price,2,CLR_NONE);
if(result!=true) { error=GetLastError(); Print("LastError = ",error); }
else error=0;
if(error==135) RefreshRates();
else break;
}
}
else OrderDelete(OrderTicket());
}
else Print( "Error when order select ", GetLastError());
//----
}
全部平仓代码。自己去弄成个函数,自己想在哪平仓就在哪平仓 |