龙听期货论坛's Archiver

C
+
+


 微信: QQ:

龙听 发表于 2017-10-30 15:26

[转载]EA自定义函数-全部平仓

[code]
bool ClosePosition()//Close all pending and holding positions
{
bool Flag=true;
int tick[200],tp[200];
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[j]=OrderTicket();
tp[j]=OrderType();
}
}
if (j!=0)
{
for(i=1;i<=j;i++)
{
OrderSelect(tick[i], SELECT_BY_TICKET);
switch(tp[i])
{
case OP_BUY:
if(OrderClose(tick[i],OrderLots(),Bid,3,CLR_NONE)==false) Flag=false;
break;
case OP_SELL:
if(OrderClose(tick[i],OrderLots(),Ask,3,CLR_NONE)==false) Flag=false;
break;
}
}
}
return(Flag);
}
[/code]

页: [1]