自定义函数:一键全部平仓
bool ClosePosition()//Close all pending and holding positions{
bool Flag=true;
int tick,tp;
int j=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicHunDun))
{
j=j+1;
tick=OrderTicket();
tp=OrderType();
}
}
if (j!=0)
{
for(i=1;i<=j;i++)
{
OrderSelect(tick, SELECT_BY_TICKET);
switch(tp)
{
case OP_BUY:
if(OrderClose(tick,OrderLots(),Bid,3,CLR_NONE)==false) Flag=false;
break;
case OP_SELL:
if(OrderClose(tick,OrderLots(),Ask,3,CLR_NONE)==false) Flag=false;
break;
}
}
}
return(Flag);
}
页:
[1]