[软件疑问]EA为什么不能强制平仓成功
void OnTick()
{
if (AccountInfoDouble(ACCOUNT_PROFIT) >3)
{
CloseAllOrder();
}
}
void CloseAllOrder()
{
int lia_0[200];
int l_index_4 = 0;
int ticket_value =0;
int l_pos_8 =0;
for (l_pos_8=0; l_pos_8 < OrdersTotal(); l_pos_8++)
{
OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);
l_index_4++;
lia_0[l_index_4] = OrderTicket();
Print("全部平仓! :", lia_0[l_index_4]);
}
if (l_index_4 != 0)
{
for (l_pos_8 = 1; l_pos_8 <= l_index_4; l_pos_8++)
{
OrderSelect(lia_0[l_pos_8], SELECT_BY_TICKET);
if (OrderType() == OP_BUY)
{
ticket_value = OrderTicket();
if (OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 100))
{
Print("多头平仓成功",ticket_value );
}
else
{
Print("多头平仓失败",ticket_value);
}
}
if (OrderType() == OP_SELL)
{
ticket_value = OrderTicket();
if (OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 100))
{
Print("空头平仓成功",ticket_value);
}
else
{
Print("空头平仓失败",ticket_value);
}
}
}
}我的想法是,只要总盈利>3, 那么就强制平掉所有单子,就算价格有变动也强平了。我这个EA代码为什么有时候可以成功,有时候常常提示平仓失败。哪里有错误吗?
发表于:2017-09-20 06:25只看该作者
2楼
请大神详解一下,感激感谢~
韬客社区www.talkfx.co