I’m not very familiar with mt4.
I want to close any sell position that is available, and if it is not available open a new buy position every time that function is executed. any solution or idea. I would greatly appreciate it. I am trying doing by this code but not working.order not closing.
///////
bool deleteLastSell()
{
bool success = true;
int lastSellOrder = -1;
for (int i = OrdersTotal() - 1; i >= 0; --i)
{
if (OrderSelect(i, SELECT_BY_POS))
{
if (OrderType() == OP_SELL)
{
lastSellOrder = i;
break;
}
}
}
if (lastSellOrder != -1)
{
if (!OrderClose(OrderSelect(lastSellOrder, SELECT_BY_POS), OrderLots(), Bid, Slippage))
{
Alert("Order #", OrderTicket(), " was not closed");
success = false;
}
}
else
{
Alert("No sell orders to delete");
}
return success;
}
//////////
New contributor
Manyaz Tablets y Electronicos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.