My goal with the bold scripts below is to try to close 2 active orders.
Assume that we are using an MT4 account with fifo rules. Thus...the oldest of the 2 orders must be closed first. Here is the code.....
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrdersTotal() == 2 && AccountProfit() > 100 && OrderType() == OP_BUY)
{OrderClose(OrderTicket(),OrderLots (),Bid,50,Green);
Sleep(3000);
OrderClose(OrderTicket(),OrderLots( ),Bid,50,Green);}
My question about the above code is as follows.......
Lets assume that the 'if' condition is true.....then the rest of the commands must then follow, correct?
OK....lets say the first order(position 0) closes as it should. Now....notice that 2nd OrderClose line which I was hoping would close the 2nd order.
Will that indeed close the 2nd order or will it be trying to close the 1st order(pos 0) that was just closed. Would'nt the program have to finish the loop and wait for the next tick before it registers that that first position was closed?
Would the better code be?............
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrdersTotal() == 2 && AccountProfit() > 100 && OrderType() == OP_BUY)
{OrderClose(OrderTicket(),OrderLots (),Bid,50,Green);
Sleep(3000);
OrderSelect(1,SELECT_BY_POS,MODE_TRADES);
OrderClose(OrderTicket(),OrderLots( ),Bid,50,Green);}
I know there are better ways to write the code but I am really interested in finding out if the OrderSelect() positions are changed instantaneously when an order is closed. Or...does it not change until the next tick where by the program returns to the start function??
Any help with the answer to this would be most appreciated.
Assume that we are using an MT4 account with fifo rules. Thus...the oldest of the 2 orders must be closed first. Here is the code.....
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrdersTotal() == 2 && AccountProfit() > 100 && OrderType() == OP_BUY)
{OrderClose(OrderTicket(),OrderLots (),Bid,50,Green);
Sleep(3000);
OrderClose(OrderTicket(),OrderLots( ),Bid,50,Green);}
My question about the above code is as follows.......
Lets assume that the 'if' condition is true.....then the rest of the commands must then follow, correct?
OK....lets say the first order(position 0) closes as it should. Now....notice that 2nd OrderClose line which I was hoping would close the 2nd order.
Will that indeed close the 2nd order or will it be trying to close the 1st order(pos 0) that was just closed. Would'nt the program have to finish the loop and wait for the next tick before it registers that that first position was closed?
Would the better code be?............
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrdersTotal() == 2 && AccountProfit() > 100 && OrderType() == OP_BUY)
{OrderClose(OrderTicket(),OrderLots (),Bid,50,Green);
Sleep(3000);
OrderSelect(1,SELECT_BY_POS,MODE_TRADES);
OrderClose(OrderTicket(),OrderLots( ),Bid,50,Green);}
I know there are better ways to write the code but I am really interested in finding out if the OrderSelect() positions are changed instantaneously when an order is closed. Or...does it not change until the next tick where by the program returns to the start function??
Any help with the answer to this would be most appreciated.