Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 70

 
wishmast:

Please tell me why the OrdersTotal() function will write -1 when searching for orders.

Example: for (i=OrdersTotal()-1 ;i>=0; i--)

why not just OrdersTotal()?

Does the count of orders in this function start from 0 or 1? That is, if there is one order, is OrdersTotal() equal to 0 or 1?

counting from zero
 
wishmast:

Please tell me why the OrdersTotal() function will write -1 when searching for orders.

Example: for (i=OrdersTotal()-1 ;i>=0; i--)

why not just OrdersTotal()?

Does the count of orders in this function start from 0 or 1? That is, if there is one order, does OrdersTotal() equal 0 or 1?

TheOrdersTotal() shows the quantity, i.e., if there is one order, thenthe OrdersTotal() will equal 1, but in the list of orders, the report starts with 0

0 - first order

1 - second order

2 - third

and so on.

So, if we start the search from the end of the list, we have tosubtract one from the total number ofOrdersTotal().

 
Sergey Gritsay:

OrdersTotal() shows the quantity, i.e. if there is one order, thenOrdersTotal() will be one, but in the list of orders the report starts from zero

0 - first order

1 - second order

2 - third

and so on.

So, if we start the search from the end of the list, we have tosubtract one from the total number ofOrdersTotal().

But if we don't subtract one from the first expression, it won't be an error, because if we have one order, two iterations will happen. Unless we don't need to make two iterations when we can do everything we need in one, so -1, right?
 
wishmast:
But if the first expression does not subtract one, it will not be an error, if we have one order, two iterations will happen. Unless there is no need to do two iterations when everything we need can be done in one, so -1, right?
Yes, that's right.
 
Sergey Gritsay:
Yes correct

Not quite right.

You can use prefix decrement.

for(int i = OrdersTotal(); i >= 0; --i)
 
trader781:
Since we have a stack of orders, why can't we just pull out the one we need? (The right ones) and do with them what we want? For example order (i-4)
Because it will only work in the MT4 tester. Or when trading on only one symbol and only one this EA.
 
Vitalie Postolache:
Because this will only work in the MT4 tester. Or when trading on only one symbol and only one this EA.

If you think about it, the EA is the same for every pair, only the account balance is common (the switch will be the last)

the filter goes to all orders satisfying the condition market-open by the Expert Advisor-if the symbol coincides

what is wrong?

 
trader781:

If you think about it, the EA is the same for every pair, only the account balance is common (the switch will be the last)

the filter goes to all orders which satisfy the condition market-open by the EA-if the simulation matches

what is wrong?

Well, it has already been explained to you above what is wrong. We can count orders as ours only and take array indexes by total amount - we will get an array with empty cells. And what is this for? And if the array was not empty, the "unnecessary" fields will contain unnecessary rubbish that will lead to errors, and we are talking about money.
 
Vitalie Postolache:
Well it has already been explained to you above what is wrong. Orders count only their own, and take the array indexes for the total number - you get an array with empty cells. And what is this for? And if the array was not empty, the "unnecessary" fields will contain unnecessary trash that will lead to errors, and we are talking about money.

OK, that's how it works.

struct myorder
{
int    Ticket;
double orderopenprice;
int   ordertype;
double profit;
double stoploss;
double  lot;
};

myorder orders[];

int i;
int count1=0;
void CalcOrders()
{
for(i=OrdersTotal()-1; i>=0; i--)
     {
      if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) && (OrderSymbol()==Symbol())
         && (OrderMagicNumber()==Magic) && (OrderType()<2))
         orders[count1].Ticket=OrderTicket();
         orders[count1].lot=OrderLots();
         orders[count1].orderopenprice=OrderOpenPrice();
         orders[count1].ordertype=OrderType();
         orders[count1].profit=OrderProfit();
         orders[count1].stoploss=OrderStopLoss();
         count1++;
     }
}    


right?

 
Help me write down the condition: If the amount of available funds in the account is less than 50% of the deposit then {action} MT5
Reason: