首页学院交易策略EA智能交易文章详细

通用自定义函数

外汇网2021-06-17 09:41:59 42
汇外网 - 全球专业的黄金外汇门户导航行情资讯网站

void CloseAllOrder()//平掉所有仓位包含挂单

{

int tick[200];

PingFlag=0;

int j=0;

for(int i=0;i

i++)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)

{j=j+1;

tick[j]=OrderTicket();

Print("全部平仓! :",tick[j]);

}

}

if (j!=0)

{

for(i=1;i<=j;i++)

{

OrderSelect(tick, SELECT_BY_TICKET);

if(OrderType()==OP_BUY)

{

if(OrderClose(OrderTicket(),OrderLots(),Bid,滑点可接受规模)==false)

{

PingFlag=1;

Print("多头平仓失利"+GetLastError());

}

}

//OrderSelect(tick, SELECT_BY_TICKET);

if(OrderType()==OP_BUYSTOP)

{

if(OrderDelete(OrderTicket(),CLR_NONE)==false)

{

PingFlag=1;

Print("多头挂单撤消失利"+GetLastError());

}

}

//OrderSelect(tick, SELECT_BY_TICKET);

if(OrderType()==OP_BUYLIMIT)

{

if(OrderDelete(OrderTicket(),CLR_NONE)==false)

{

PingFlag=1;

Print("多头挂单撤消失利"+GetLastError());

}

}

if(OrderType()==OP_SELL)

{

if(OrderClose(OrderTicket(),OrderLots(),Ask,滑点可接受规模)==false)

{

PingFlag=1;

Print("空头平仓失利"+GetLastError());

}

}

if(OrderType()==OP_SELLSTOP)

{

if(OrderDelete(OrderTicket(),CLR_NONE)==false)

{

PingFlag=1;

Print("空头挂单撤消失利"+GetLastError());

}

}

if(OrderType()==OP_SELLLIMIT)

{

if(OrderDelete(OrderTicket(),CLR_NONE)==false)

{

PingFlag=1;

Print("空头挂单撤消失利"+GetLastError());

}

}

}

}

if (PingFlag==0) PingStop=1;

}

标签:

随机快审展示
加入快审,优先展示

加入VIP