Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 70
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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?
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().
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 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 correct
Not quite right.
You can use prefix decrement.
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 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?
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. 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.
{
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?