for(int i=0; i< OrdersTotal(); i++) // For market and pending orders
{
if((OrderSelect(i,SELECT_BY_POS)==true) //If there is the next one
&& (OrderSymbol()==Symbol()) && OrderMagicNumber() == Magic_A )
{
This is the loop given in the book mql4 to create array for order.
Will the OrdersTotal() decrease by itself each time an order is closed ?
for(int i=1; i<=OrdersTotal(); i++) // Order searching cycle
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
{ // Order analysis://----------------------------------------------------------------------- 3 --if (OrderSymbol()!= Symb) continue;
int TotalNumberOfOrders; // <-- this variable will hold the number of orders currently in the Trade pool
TotalNumberOfOrders = OrdersTotal(); // <-- we store the number of Orders in the variablefor(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --) // <-- for loop to loop through all Orders . . COUNT DOWN TO ZERO !
Is it okay not to declare TotalNumberOfOrders = OrdersTotal() ;
I'm currently using that but I'm not sure about to output even though it is the same . Since OrdersTotal() is in the for loop, will closing 1 order affect the OrdersTotal again and again ?
juniorlcq: I'm currently using that but I'm not sure about to output even though it is the same . Since OrdersTotal() is in the for loop, will closing 1 order affect the OrdersTotal again and again ?
No, because you are not checking OrdersTotal, you are checking PositionIndex as the condition to continue the loop
Jimdandy: The only time I have been forced to use the count up method instead of the countdown method was on a broker that was really anal about FIFO and would not let me close the newest trade first.... how stupid.
In that case, capture all relevant ticket numbers (in an array) and then close. Don't count up AND close.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
What if we do a loop like this one,
This is the loop given in the book mql4 to create array for order.
Will the OrdersTotal() decrease by itself each time an order is closed ?
//***************************************************************************
I just have a look in the book, below is the loop given to close an order, so the anwers is yes : ( https://book.mql4.com/trading/orderclose )
What if we do a loop like this one,
This is the loop given in the book mql4 to create array for order.
Will the OrdersTotal() decrease by itself each time an order is closed ?
Is it okay not to declare TotalNumberOfOrders = OrdersTotal() ;
What I mean was straight away use OrdersTotal()
for ( x = OrdersTotal() - 1 ...... )
I'm currently using that but I'm not sure about to output even though it is the same . Since OrdersTotal() is in the for loop, will closing 1 order affect the OrdersTotal again and again ?
No, because you are not checking OrdersTotal, you are checking PositionIndex as the condition to continue the loop
Excellent job of explaining this topic! Without out the graphics it's just impossible to explain... Well done.
The only time I have been forced to use the count up method instead of the countdown method was on a broker
that was really xxx about FIFO and would not let me close the newest trade first.... how stupid.
Again I say ... well done...
Hi experts, what is your opinion about this solution?