mql4写一个一键平仓
在MQL4中,您可以使用以下代码编写一个一键平仓的函数:
void CloseAllPositions()
{
int total = OrdersTotal();
for (int i = total - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 0, clrNone))
{
Print("Order closed: ", OrderTicket());
}
else
{
Print("Failed to close order: ", OrderTicket(), " Error: ", GetLastError());
}
}
}
}
您可以将上述代码添加到您的MQL4脚本中,然后在需要一键平仓时调用CloseAllPositions()函数即可。该函数会遍历所有的订单,并使用OrderClose()函数进行平仓操作
原文地址: http://www.cveoy.top/t/topic/iJIN 著作权归作者所有。请勿转载和采集!