Hello all,
Not much of a programmer here...but I have managed to put some MT4 code together a time or two. Anyhow....the following code is my attempt to close a bundle of 3 trades and obey the fifo rules. For some reason though...I cannot get the code to work. It only closes the 1st order of 3. I need all the orders to close once the if condition is met. Here is the part of the code.
if (otot == 3 && z0 >= 50 && z1 >= 50 && z2 >= 50 && apr >= LT3A && OrderType() == OP_BUY)
{OrderClose(OrderTicket(),OrderLots(),Bid,50,Green);
Sleep(3000);
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
OrderClose(OrderTicket(),OrderLots(),Bid,50,Green);
Sleep(3000);
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
OrderClose(OrderTicket(),OrderLots(),Bid,50,Green);
if (OrdersTotal() > 0)
OrderClose(OrderTicket(),OrderLots(),Bid,50,Green);}
Again....the above code carrys out the 1st Orderclose....but it does not carry out the rest of the trade. Is the sleep command the problem?
I know there are better ways to write this but I am puzzled why the above wont work. Any help would be appreciated.
Not much of a programmer here...but I have managed to put some MT4 code together a time or two. Anyhow....the following code is my attempt to close a bundle of 3 trades and obey the fifo rules. For some reason though...I cannot get the code to work. It only closes the 1st order of 3. I need all the orders to close once the if condition is met. Here is the part of the code.
if (otot == 3 && z0 >= 50 && z1 >= 50 && z2 >= 50 && apr >= LT3A && OrderType() == OP_BUY)
{OrderClose(OrderTicket(),OrderLots(),Bid,50,Green);
Sleep(3000);
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
OrderClose(OrderTicket(),OrderLots(),Bid,50,Green);
Sleep(3000);
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
OrderClose(OrderTicket(),OrderLots(),Bid,50,Green);
if (OrdersTotal() > 0)
OrderClose(OrderTicket(),OrderLots(),Bid,50,Green);}
Again....the above code carrys out the 1st Orderclose....but it does not carry out the rest of the trade. Is the sleep command the problem?
I know there are better ways to write this but I am puzzled why the above wont work. Any help would be appreciated.